From ac63e21033bec73693380d2c61f696ba51b05dff Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 22 Jan 2024 22:32:00 +0000 Subject: [PATCH] finish tests for HW bigtable --- .../generate_composed_library.py | 3 +- .../test/generate_library_integration_test.sh | 148 ++++++++++-------- library_generation/utilities.py | 9 ++ 3 files changed, 92 insertions(+), 68 deletions(-) diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index 622bf79cd6..242e79c03c 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -65,7 +65,7 @@ def generate_composed_library( base_arguments += util.create_argument('protobuf_version', config) destination_path = f'java-{library.api_shortname}' - if config.destination_path is not None: + if config.destination_path == 'google-cloud-java': destination_path = config.destination_path + '/' + destination_path versions_file = '' @@ -77,6 +77,7 @@ def generate_composed_library( versions_file = f'{output_folder}/google-cloud-java/versions.txt' else: print('this is a HW library') + util.delete_if_exists(f'{output_folder}/{destination_path}') clone_out = util.sh_util(f'git clone "https://github.com/googleapis/{destination_path}.git"', cwd=output_folder) print(clone_out) versions_file = f'{output_folder}/{destination_path}/versions.txt' diff --git a/library_generation/test/generate_library_integration_test.sh b/library_generation/test/generate_library_integration_test.sh index caef966c5d..eeb3858130 100755 --- a/library_generation/test/generate_library_integration_test.sh +++ b/library_generation/test/generate_library_integration_test.sh @@ -51,78 +51,92 @@ if [ -f "${output_folder}/generation_times" ];then rm "${output_folder}/generation_times" fi -configuration_yaml="${script_dir}/resources/integration/google-cloud-java/generation_config.yaml" -library_api_shortnames=$(py_util "get_configuration_yaml_library_api_shortnames" "${configuration_yaml}") - -for api_shortname in ${library_api_shortnames}; do - pushd "${output_folder}" - - echo "Generating library ${api_shortname}..." - generation_start=$(date "+%s") - python3 "${library_generation_dir}"/main.py generate-from-yaml \ - --generation-config-yaml "${configuration_yaml}" \ - --enable-postprocessing "${enable_postprocessing}" \ - --target-library-api-shortname "${api_shortname}" - generation_end=$(date "+%s") - - # some generations are less than 1 second (0 produces exit code 1 in `expr`) - generation_duration_seconds=$(expr "${generation_end}" - "${generation_start}" || true) - echo "Generation time for ${api_shortname} was ${generation_duration_seconds} seconds." - pushd "${output_folder}" - echo "${proto_path} ${generation_duration_seconds}" >> generation_times - - echo "Generate library finished." - echo "Compare generation result..." - if [ ${enable_postprocessing} == "true" ]; then - echo "Checking out repository..." - target_folder="${output_folder}/google-cloud-java/java-${api_shortname}" - pushd "${target_folder}" - source_diff_result=0 - git diff \ - --ignore-space-at-eol \ - -r \ - --exit-code \ - -- \ - ':!*pom.xml' \ - ':!*README.md' \ - ':!*gapic_metadata.json' \ - ':!*reflect-config.json' \ - ':!*package-info.java' \ - || source_diff_result=$? - - pom_diff_result=$(compare_poms "${target_folder}") - popd # target_folder - if [[ ${source_diff_result} == 0 ]] && [[ ${pom_diff_result} == 0 ]] ; then - echo "SUCCESS: Comparison finished, no difference is found." - # Delete google-cloud-java to allow a sparse clone of the next library - rm -rdf google-cloud-java - elif [ ${source_diff_result} != 0 ]; then - echo "FAILURE: Differences found in proto path: java-${api_shortname}." - exit "${source_diff_result}" - elif [ ${pom_diff_result} != 0 ]; then - echo "FAILURE: Differences found in generated java-${api_shortname}'s poms" - exit "${pom_diff_result}" - fi - elif [ "${enable_postprocessing}" == "false" ]; then - for proto_path in "${proto_paths[@]}"; do - destination_path=$(compute_destination_path "${proto_path}" "${output_folder}") - # include gapic_metadata.json and package-info.java after - # resolving https://github.com/googleapis/sdk-platform-java/issues/1986 +#configuration_yaml="${script_dir}/resources/integration/google-cloud-java/generation_config.yaml" +declare -a configuration_yamls=( + "${script_dir}/resources/integration/java-bigtable/generation_config.yaml" + "${script_dir}/resources/integration/google-cloud-java/generation_config.yaml" +) + + +for configuration_yaml in ${configuration_yamls[@]}; do + library_api_shortnames=$(py_util "get_configuration_yaml_library_api_shortnames" "${configuration_yaml}") + destination_path=$(py_util "get_configuration_yaml_destination_path" "${configuration_yaml}") + + for api_shortname in ${library_api_shortnames}; do + pushd "${output_folder}" + + echo "Generating library ${api_shortname}..." + generation_start=$(date "+%s") + python3 "${library_generation_dir}"/main.py generate-from-yaml \ + --generation-config-yaml "${configuration_yaml}" \ + --enable-postprocessing "${enable_postprocessing}" \ + --target-library-api-shortname "${api_shortname}" + generation_end=$(date "+%s") + + # some generations are less than 1 second (0 produces exit code 1 in `expr`) + generation_duration_seconds=$(expr "${generation_end}" - "${generation_start}" || true) + echo "Generation time for ${api_shortname} was ${generation_duration_seconds} seconds." + pushd "${output_folder}" + echo "${proto_path} ${generation_duration_seconds}" >> generation_times + + echo "Generate library finished." + echo "Compare generation result..." + if [ ${enable_postprocessing} == "true" ]; then + echo "Checking out repository..." + if [[ "${destination_path}" == *google-cloud-java* ]]; then + target_folder="${output_folder}/google-cloud-java/java-${api_shortname}" + else + target_folder="${output_folder}/java-${api_shortname}" + fi + + pushd "${target_folder}" source_diff_result=0 - diff --strip-trailing-cr -r "googleapis-gen/${proto_path}/${destination_path}" "${output_folder}/${destination_path}" \ - -x "*gradle*" \ - -x "gapic_metadata.json" \ - -x "package-info.java" || source_diff_result=$? - if [ ${source_diff_result} == 0 ] ; then + git diff \ + --ignore-space-at-eol \ + -r \ + --exit-code \ + -- \ + ':!*pom.xml' \ + ':!*README.md' \ + ':!*gapic_metadata.json' \ + ':!*reflect-config.json' \ + ':!*package-info.java' \ + || source_diff_result=$? + + pom_diff_result=$(compare_poms "${target_folder}") + popd # target_folder + if [[ ${source_diff_result} == 0 ]] && [[ ${pom_diff_result} == 0 ]] ; then echo "SUCCESS: Comparison finished, no difference is found." - else - echo "FAILURE: Differences found in proto path: ${proto_path}." + # Delete google-cloud-java to allow a sparse clone of the next library + rm -rdf google-cloud-java + elif [ ${source_diff_result} != 0 ]; then + echo "FAILURE: Differences found in proto path: java-${api_shortname}." exit "${source_diff_result}" + elif [ ${pom_diff_result} != 0 ]; then + echo "FAILURE: Differences found in generated java-${api_shortname}'s poms" + exit "${pom_diff_result}" fi - done - fi + elif [ "${enable_postprocessing}" == "false" ]; then + for proto_path in "${proto_paths[@]}"; do + destination_path=$(compute_destination_path "${proto_path}" "${output_folder}") + # include gapic_metadata.json and package-info.java after + # resolving https://github.com/googleapis/sdk-platform-java/issues/1986 + source_diff_result=0 + diff --strip-trailing-cr -r "googleapis-gen/${proto_path}/${destination_path}" "${output_folder}/${destination_path}" \ + -x "*gradle*" \ + -x "gapic_metadata.json" \ + -x "package-info.java" || source_diff_result=$? + if [ ${source_diff_result} == 0 ] ; then + echo "SUCCESS: Comparison finished, no difference is found." + else + echo "FAILURE: Differences found in proto path: ${proto_path}." + exit "${source_diff_result}" + fi + done + fi - popd # output_folder + popd # output_folder + done done echo "ALL TESTS SUCCEEDED" echo "generation times in seconds (does not consider repo checkout):" diff --git a/library_generation/utilities.py b/library_generation/utilities.py index 906773bdea..50834e4411 100755 --- a/library_generation/utilities.py +++ b/library_generation/utilities.py @@ -30,6 +30,15 @@ def get_configuration_yaml_library_api_shortnames(generation_config_yaml): result += f'{library.api_shortname} ' return result[:-1] +""" +For a given configuration yaml path, it returns the destination_path +entry at the root of the yaml +""" +def get_configuration_yaml_destination_path(generation_config_yaml): + config = GenerationConfig.from_yaml(generation_config_yaml) + return config.destination_path or '' + + """ Calls a function defined in library_generation/utilities.sh """