|
20 | 20 | import os
|
21 | 21 | import io
|
22 | 22 | import contextlib
|
23 |
| -import subprocess |
24 | 23 | from pathlib import Path
|
25 | 24 | from difflib import unified_diff
|
26 | 25 | from typing import List
|
27 |
| - |
| 26 | +from parameterized import parameterized |
28 | 27 | from library_generation import utilities as util
|
29 | 28 | from library_generation.model.gapic_config import GapicConfig
|
30 | 29 | from library_generation.model.generation_config import GenerationConfig
|
31 | 30 | from library_generation.model.gapic_inputs import parse as parse_build_file
|
| 31 | +from library_generation.model.generation_config import from_yaml |
32 | 32 | from library_generation.model.library_config import LibraryConfig
|
33 | 33 |
|
34 | 34 | script_dir = os.path.dirname(os.path.realpath(__file__))
|
35 | 35 | resources_dir = os.path.join(script_dir, "resources")
|
36 | 36 | build_file = Path(os.path.join(resources_dir, "misc")).resolve()
|
| 37 | +test_config_dir = Path(os.path.join(resources_dir, "test-config")).resolve() |
37 | 38 | library_1 = LibraryConfig(
|
38 | 39 | api_shortname="baremetalsolution",
|
39 | 40 | name_pretty="Bare Metal Solution",
|
@@ -104,6 +105,101 @@ def test_eprint_valid_input_succeeds(self):
|
104 | 105 | # print() appends a `\n` each time it's called
|
105 | 106 | self.assertEqual(test_input + "\n", result)
|
106 | 107 |
|
| 108 | + # parameterized tests need to run from the class, see |
| 109 | + # https://github.com/wolever/parameterized/issues/37 for more info. |
| 110 | + # This test confirms that a ValueError with an error message about a |
| 111 | + # missing key (specified in the first parameter of each `parameterized` |
| 112 | + # tuple) when parsing a test configuration yaml (second parameter) will |
| 113 | + # be raised. |
| 114 | + @parameterized.expand( |
| 115 | + [ |
| 116 | + ("libraries", f"{test_config_dir}/config_without_libraries.yaml"), |
| 117 | + ("GAPICs", f"{test_config_dir}/config_without_gapics.yaml"), |
| 118 | + ("proto_path", f"{test_config_dir}/config_without_proto_path.yaml"), |
| 119 | + ("api_shortname", f"{test_config_dir}/config_without_api_shortname.yaml"), |
| 120 | + ( |
| 121 | + "api_description", |
| 122 | + f"{test_config_dir}/config_without_api_description.yaml", |
| 123 | + ), |
| 124 | + ("name_pretty", f"{test_config_dir}/config_without_name_pretty.yaml"), |
| 125 | + ( |
| 126 | + "product_documentation", |
| 127 | + f"{test_config_dir}/config_without_product_docs.yaml", |
| 128 | + ), |
| 129 | + ( |
| 130 | + "gapic_generator_version", |
| 131 | + f"{test_config_dir}/config_without_generator.yaml", |
| 132 | + ), |
| 133 | + ( |
| 134 | + "googleapis_commitish", |
| 135 | + f"{test_config_dir}/config_without_googleapis.yaml", |
| 136 | + ), |
| 137 | + ("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"), |
| 138 | + ("synthtool_commitish", f"{test_config_dir}/config_without_synthtool.yaml"), |
| 139 | + ( |
| 140 | + "template_excludes", |
| 141 | + f"{test_config_dir}/config_without_temp_excludes.yaml", |
| 142 | + ), |
| 143 | + ] |
| 144 | + ) |
| 145 | + def test_from_yaml_without_key_fails(self, error_message_contains, path_to_yaml): |
| 146 | + self.assertRaisesRegex( |
| 147 | + ValueError, |
| 148 | + error_message_contains, |
| 149 | + from_yaml, |
| 150 | + path_to_yaml, |
| 151 | + ) |
| 152 | + |
| 153 | + def test_from_yaml_succeeds(self): |
| 154 | + config = from_yaml(f"{test_config_dir}/generation_config.yaml") |
| 155 | + self.assertEqual("2.34.0", config.gapic_generator_version) |
| 156 | + self.assertEqual(25.2, config.protobuf_version) |
| 157 | + self.assertEqual( |
| 158 | + "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish |
| 159 | + ) |
| 160 | + self.assertEqual( |
| 161 | + "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", |
| 162 | + config.owlbot_cli_image, |
| 163 | + ) |
| 164 | + self.assertEqual( |
| 165 | + "6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish |
| 166 | + ) |
| 167 | + self.assertEqual( |
| 168 | + [ |
| 169 | + ".github/*", |
| 170 | + ".kokoro/*", |
| 171 | + "samples/*", |
| 172 | + "CODE_OF_CONDUCT.md", |
| 173 | + "CONTRIBUTING.md", |
| 174 | + "LICENSE", |
| 175 | + "SECURITY.md", |
| 176 | + "java.header", |
| 177 | + "license-checks.xml", |
| 178 | + "renovate.json", |
| 179 | + ".gitignore", |
| 180 | + ], |
| 181 | + config.template_excludes, |
| 182 | + ) |
| 183 | + library = config.libraries[0] |
| 184 | + self.assertEqual("cloudasset", library.api_shortname) |
| 185 | + self.assertEqual("Cloud Asset Inventory", library.name_pretty) |
| 186 | + self.assertEqual( |
| 187 | + "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview", |
| 188 | + library.product_documentation, |
| 189 | + ) |
| 190 | + self.assertEqual( |
| 191 | + "provides inventory services based on a time series database.", |
| 192 | + library.api_description, |
| 193 | + ) |
| 194 | + self.assertEqual("asset", library.library_name) |
| 195 | + gapics = library.gapic_configs |
| 196 | + self.assertEqual(5, len(gapics)) |
| 197 | + self.assertEqual("google/cloud/asset/v1", gapics[0].proto_path) |
| 198 | + self.assertEqual("google/cloud/asset/v1p1beta1", gapics[1].proto_path) |
| 199 | + self.assertEqual("google/cloud/asset/v1p2beta1", gapics[2].proto_path) |
| 200 | + self.assertEqual("google/cloud/asset/v1p5beta1", gapics[3].proto_path) |
| 201 | + self.assertEqual("google/cloud/asset/v1p7beta1", gapics[4].proto_path) |
| 202 | + |
107 | 203 | def test_gapic_inputs_parse_grpc_only_succeeds(self):
|
108 | 204 | parsed = parse_build_file(build_file, "", "BUILD_grpc.bazel")
|
109 | 205 | self.assertEqual("grpc", parsed.transport)
|
@@ -252,9 +348,11 @@ def test_generate_prerequisite_files_success(self):
|
252 | 348 | f"{library_path}/owlbot.py",
|
253 | 349 | ]
|
254 | 350 | self.__cleanup(files)
|
| 351 | + config = self.__get_a_gen_config(1) |
255 | 352 | proto_path = "google/cloud/baremetalsolution/v2"
|
256 | 353 | transport = "grpc"
|
257 | 354 | util.generate_prerequisite_files(
|
| 355 | + config=config, |
258 | 356 | library=library_1,
|
259 | 357 | proto_path=proto_path,
|
260 | 358 | transport=transport,
|
@@ -357,7 +455,19 @@ def __get_a_gen_config(num: int):
|
357 | 455 | googleapis_commitish="",
|
358 | 456 | owlbot_cli_image="",
|
359 | 457 | synthtool_commitish="",
|
360 |
| - template_excludes=[], |
| 458 | + template_excludes=[ |
| 459 | + ".github/*", |
| 460 | + ".kokoro/*", |
| 461 | + "samples/*", |
| 462 | + "CODE_OF_CONDUCT.md", |
| 463 | + "CONTRIBUTING.md", |
| 464 | + "LICENSE", |
| 465 | + "SECURITY.md", |
| 466 | + "java.header", |
| 467 | + "license-checks.xml", |
| 468 | + "renovate.json", |
| 469 | + ".gitignore", |
| 470 | + ], |
361 | 471 | path_to_yaml=".",
|
362 | 472 | libraries=libraries,
|
363 | 473 | )
|
|
0 commit comments