Skip to content

Commit 89381c7

Browse files
chore: recursive comparison in hermetic build IT (#2542)
Fixes #2540 Sample error message when running `library_generation/test/integration_tests.py` ``` Generation finished successfully. Will now compare differences between generated and existing libraries ****************************** Checking for differences in 'java-apigee-connect'. The expected library is in /usr/local/google/home/diegomarquezp/Desktop/sdk-platform-java/library_generation/test/resources/integration/golden/java-apigee-connect. The actual library is in /usr/local/google/home/diegomarquezp/Desktop/sdk-platform-java/library_generation/output/google-cloud-java/java-apigee-connect. Some files (found in both folders) are differing: - README.md - proto-google-cloud-apigee-connect-v1/src/main/java/com/google/cloud/apigeeconnect/v1/ConnectionProto.java ```
1 parent 5dfd17e commit 89381c7

File tree

4 files changed

+75
-42
lines changed

4 files changed

+75
-42
lines changed

library_generation/test/integration_tests.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_get_commit_message_success(self):
7676
cmp(
7777
f"{config_dir}/{repo}/pr-description-golden.txt",
7878
f"{description_file}",
79-
)
79+
), "The generated PR description does not match the expected golden file"
8080
)
8181
os.remove(f"{description_file}")
8282

@@ -107,16 +107,17 @@ def test_generate_repo(self):
107107
generation_config_yaml=config_file, repository_path=repo_dest
108108
)
109109
# compare result
110+
print(
111+
"Generation finished successfully. Will now compare differences between generated and existing libraries"
112+
)
110113
for library_name in library_names:
111114
actual_library = (
112115
f"{repo_dest}/{library_name}" if config.is_monorepo else repo_dest
113116
)
114-
print(
115-
f"Generation finished. Will now compare "
116-
f"the expected library in {golden_dir}/{library_name}, "
117-
f"with the actual library in {actual_library}. "
118-
f"Compare generation result: "
119-
)
117+
print("*" * 50)
118+
print(f"Checking for differences in '{library_name}'.")
119+
print(f" The expected library is in {golden_dir}/{library_name}.")
120+
print(f" The actual library is in {actual_library}. ")
120121
target_repo_dest = (
121122
f"{repo_dest}/{library_name}" if config.is_monorepo else repo_dest
122123
)
@@ -125,20 +126,40 @@ def test_generate_repo(self):
125126
target_repo_dest,
126127
ignore=[".repo-metadata.json"],
127128
)
129+
diff_files = []
130+
golden_only = []
131+
generated_only = []
128132
# compare source code
129-
self.assertEqual([], compare_result.left_only)
130-
self.assertEqual([], compare_result.right_only)
131-
self.assertEqual([], compare_result.diff_files)
132-
print("Source code comparison succeed.")
133+
self.__recursive_diff_files(
134+
compare_result, diff_files, golden_only, generated_only
135+
)
136+
137+
# print all found differences for inspection
138+
print_file = lambda f: print(f" - {f}")
139+
if len(diff_files) > 0:
140+
print(" Some files (found in both folders) are differing:")
141+
[print_file(f) for f in diff_files]
142+
if len(golden_only) > 0:
143+
print(" There were files found only in the golden dir:")
144+
[print_file(f) for f in golden_only]
145+
if len(generated_only) > 0:
146+
print(" Some files were found to have differences:")
147+
[print_file(f) for f in generated_only]
148+
149+
self.assertTrue(len(golden_only) == 0)
150+
self.assertTrue(len(generated_only) == 0)
151+
self.assertTrue(len(diff_files) == 0)
152+
153+
print(" No differences found in {library_name}")
133154
# compare .repo-metadata.json
134155
self.assertTrue(
135156
self.__compare_json_files(
136157
f"{golden_dir}/{library_name}/.repo-metadata.json",
137158
f"{target_repo_dest}/.repo-metadata.json",
138159
),
139-
msg=f"The generated {library_name}/.repo-metadata.json is different from golden.",
160+
msg=f" The generated {library_name}/.repo-metadata.json is different from golden.",
140161
)
141-
print(".repo-metadata.json comparison succeed.")
162+
print(" .repo-metadata.json comparison succeed.")
142163

143164
if not config.is_monorepo:
144165
continue
@@ -151,15 +172,15 @@ def test_generate_repo(self):
151172
False,
152173
)
153174
)
154-
print("gapic-libraries-bom/pom.xml comparison succeed.")
175+
print(" gapic-libraries-bom/pom.xml comparison succeed.")
155176
self.assertFalse(
156177
compare_xml(
157178
f"{golden_dir}/pom.xml",
158179
f"{repo_dest}/pom.xml",
159180
False,
160181
)
161182
)
162-
print("pom.xml comparison succeed.")
183+
print(" pom.xml comparison succeed.")
163184

164185
@classmethod
165186
def __pull_repo_to(cls, default_dest: Path, repo: str, committish: str) -> str:
@@ -203,7 +224,7 @@ def __get_config_files(cls, path: str) -> List[tuple[str, str]]:
203224
if sub_dir.is_file():
204225
continue
205226
repo = sub_dir.name
206-
if repo == "golden" or repo == "java-bigtable":
227+
if repo in ["golden", "java-bigtable"]:
207228
continue
208229
config = f"{sub_dir}/{config_name}"
209230
config_files.append((repo, config))
@@ -223,3 +244,24 @@ def __load_json_to_sorted_list(cls, path: str) -> List[tuple]:
223244
res = [(key, value) for key, value in data.items()]
224245

225246
return sorted(res, key=lambda x: x[0])
247+
248+
@classmethod
249+
def __recursive_diff_files(
250+
self,
251+
dcmp: dircmp,
252+
diff_files: List[str],
253+
left_only: List[str],
254+
right_only: List[str],
255+
dirname: str = "",
256+
):
257+
"""
258+
recursively compares two subdirectories. The found differences are passed to three expected list references
259+
"""
260+
append_dirname = lambda d: dirname + d
261+
diff_files.extend(map(append_dirname, dcmp.diff_files))
262+
left_only.extend(map(append_dirname, dcmp.left_only))
263+
right_only.extend(map(append_dirname, dcmp.right_only))
264+
for sub_dirname, sub_dcmp in dcmp.subdirs.items():
265+
self.__recursive_diff_files(
266+
sub_dcmp, diff_files, left_only, right_only, dirname + sub_dirname + "/"
267+
)

library_generation/test/resources/integration/google-cloud-java/generation_config.yaml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
gapic_generator_version: 2.34.0
1+
gapic_generator_version: 2.37.0
22
protobuf_version: 25.2
3-
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
3+
googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc
44
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
55
synthtool_commitish: 5e1fb2032fa44bc170677b38713023b4fec51a4e
66
template_excludes:
@@ -48,17 +48,3 @@ libraries:
4848
- proto_path: google/cloud/alloydb/connectors/v1
4949
- proto_path: google/cloud/alloydb/connectors/v1alpha
5050
- proto_path: google/cloud/alloydb/connectors/v1beta
51-
52-
- api_shortname: documentai
53-
name_pretty: Document AI
54-
product_documentation: https://cloud.google.com/compute/docs/documentai/
55-
api_description: allows developers to unlock insights from your documents with machine
56-
learning.
57-
library_name: document-ai
58-
release_level: stable
59-
issue_tracker: https://issuetracker.google.com/savedsearches/559755
60-
GAPICs:
61-
- proto_path: google/cloud/documentai/v1
62-
- proto_path: google/cloud/documentai/v1beta1
63-
- proto_path: google/cloud/documentai/v1beta2
64-
- proto_path: google/cloud/documentai/v1beta3
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
This pull request is generated with proto changes between googleapis commit a17d4caf184b050d50cacf2b0d579ce72c31ce74 (exclusive) and 1a45bf7393b52407188c82e63101db7dc9c72026 (inclusive).
1+
This pull request is generated with proto changes between googleapis commit a17d4caf184b050d50cacf2b0d579ce72c31ce74 (exclusive) and 9868a57470a969ffa1d21194a5c05d7a6e4e98cc (inclusive).
22
Qualified commits are:
3-
[googleapis/googleapis@7a9a855](https://github.com/googleapis/googleapis/commit/7a9a855287b5042410c93e5a510f40efd4ce6cb1)
4-
[googleapis/googleapis@c7fd8bd](https://github.com/googleapis/googleapis/commit/c7fd8bd652ac690ca84f485014f70b52eef7cb9e)
3+
[googleapis/googleapis@aa16fda](https://github.com/googleapis/googleapis/commit/aa16fdad909bc33e2d4ff04cfde56a46d0e52b13)
4+
[googleapis/googleapis@0733fdb](https://github.com/googleapis/googleapis/commit/0733fdb5f745192f9f3c95f8d08039286567cbcc)
55
BEGIN_NESTED_COMMIT
6-
feat: [document-ai] expose model_type in v1 processor, so that user can see the model_type after get or list processor version
6+
feat: [alloydb] support for obtaining the public IP address of an Instance
7+
feat: [alloydb] support for getting PSC DNS name from the GetConnectionInfo API
8+
feat: [alloydb] add PSC cluster and instance configuration settings to enable/disable PSC and obtain the PSC endpoint name
9+
feat: [alloydb] add new API to list the databases in a project and location
10+
docs: [alloydb] clarified read pool config is for read pool type instances
711

8-
PiperOrigin-RevId: 603727585
12+
PiperOrigin-RevId: 610475013
913

1014
END_NESTED_COMMIT
1115
BEGIN_NESTED_COMMIT
12-
feat: [document-ai] add model_type in v1beta3 processor proto
16+
feat: [alloydb] support for obtaining the public IP address of an Instance
17+
feat: [alloydb] support for getting PSC DNS name from the GetConnectionInfo API
1318

14-
PiperOrigin-RevId: 603726122
19+
PiperOrigin-RevId: 610415824
1520

1621
END_NESTED_COMMIT
1722
BEGIN_NESTED_COMMIT
18-
feat: Regenerate with the Java code generator (gapic-generator-java) v2.34.0
23+
feat: Regenerate with the Java code generator (gapic-generator-java) v2.37.0
1924
END_NESTED_COMMIT

library_generation/test/resources/integration/java-bigtable/generation_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
gapic_generator_version: 2.35.0
1+
gapic_generator_version: 2.37.0
22
protobuf_version: 25.2
3-
googleapis_commitish: fc3043ebe12fb6bc1729c175e1526c859ce751d8
3+
googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc
44
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
55
synthtool_commitish: a6fb7d5f072b75698af1cbf06c5b001565753cfb
66
template_excludes:

0 commit comments

Comments
 (0)