Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check library_name is unique among libraries #2490

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions library_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,29 @@ The library level parameters define how to generate a (multi-versions) GAPIC
library.
They are shared by all GAPICs of a library.

| Name | Required | Notes |
|:---------------------|:--------:|:------------------------------------------------------------------|
| api_shortname | Yes | |
| api_description | Yes | |
| name_pretty | Yes | |
| product_docs | Yes | |
| library_type | No | `GAPIC_AUTO` if not specified |
| release_level | No | `preview` if not specified |
| api_id | No | `{api_shortname}.googleapis.com` if not specified |
| api_reference | No | |
| client_documentation | No | |
| distribution_name | No | `{group_id}:google-{cloud_prefix}{library_name}` if not specified |
| googleapis_commitish | No | use repository level `googleapis_commitish` if not specified. |
| group_id | No | `com.google.cloud` if not specified |
| issue_tracker | No | |
| library_name | No | `api_shortname` is not specified |
| rest_documentation | No | |
| rpc_documentation | No | |
| cloud_api | No | `true` if not specified |
| requires-billing | No | `true` if not specified |
| Name | Required | Notes |
|:----------------------|:--------:|:-----------------------------------------------------------------------------------|
| api_shortname | Yes | |
| api_description | Yes | |
| name_pretty | Yes | |
| product_docs | Yes | |
| library_type | No | `GAPIC_AUTO` if not specified |
| release_level | No | `preview` if not specified |
| api_id | No | `{api_shortname}.googleapis.com` if not specified |
| api_reference | No | |
| codeowner_team | No | |
| client_documentation | No | |
| distribution_name | No | `{group_id}:google-{cloud_prefix}{library_name}` if not specified |
| excluded_poms | No | |
| excluded_dependencies | No | |
| googleapis_commitish | No | use repository level `googleapis_commitish` if not specified. |
| group_id | No | `com.google.cloud` if not specified |
| issue_tracker | No | |
| library_name | No | `api_shortname` is not specified. This value should be unique among all libraries. |
| rest_documentation | No | |
| rpc_documentation | No | |
| cloud_api | No | `true` if not specified |
| requires-billing | No | `true` if not specified |

Note that `cloud_prefix` is `cloud-` if `cloud_api` is `true`; empty otherwise.

Expand Down
27 changes: 24 additions & 3 deletions library_generation/test/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
api_description="allows you to encrypt, store, manage, and audit infrastructure and application-level secrets.",
gapic_configs=list(),
)
library_3 = LibraryConfig(
api_shortname="secret",
name_pretty="Secret Management Example",
product_documentation="https://cloud.google.com/solutions/",
api_description="allows you to encrypt, store, and audit infrastructure and application-level secrets.",
library_name="secretmanager",
gapic_configs=list(),
)


class UtilitiesTest(unittest.TestCase):
Expand Down Expand Up @@ -389,6 +397,17 @@ def test_prepare_repo_monorepo_success(self):
["java-bare-metal-solution", "java-secretmanager"], library_path
)

def test_prepare_repo_monorepo_duplicated_library_name_failed(self):
gen_config = self.__get_a_gen_config(3)
self.assertRaisesRegex(
ValueError,
"secretmanager",
util.prepare_repo,
gen_config,
gen_config.libraries,
f"{resources_dir}/misc",
)

def test_prepare_repo_monorepo_failed(self):
gen_config = self.__get_a_gen_config(2)
self.assertRaises(
Expand Down Expand Up @@ -444,15 +463,17 @@ def __compare_files(self, expect: str, actual: str):
@staticmethod
def __get_a_gen_config(num: int):
"""
Returns an object of GenerationConfig with one or two of
Returns an object of GenerationConfig with one to three of
LibraryConfig objects. Other attributes are set to empty str.
:param num: the number of LibraryConfig objects associated with
the GenerationConfig. Only support one or two.
the GenerationConfig. Only support 1, 2 or 3.
:return: an object of GenerationConfig
"""
if num > 1:
if num == 2:
libraries = [library_1, library_2]
elif num == 3:
libraries = [library_1, library_2, library_3]
else:
libraries = [library_1]

Expand Down
5 changes: 5 additions & 0 deletions library_generation/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def prepare_repo(
:param language: programming language of the library
:return: a RepoConfig object contained repository information
:raise FileNotFoundError if there's no versions.txt in repo_path
:raise ValueError if two libraries have the same library_name
"""
output_folder = sh_util("get_output_folder")
print(f"output_folder: {output_folder}")
Expand All @@ -267,6 +268,10 @@ def prepare_repo(
# use absolute path because docker requires absolute path
# in volume name.
absolute_library_path = str(Path(library_path).resolve())
if absolute_library_path in libraries:
# check whether the java_library is unique among all libraries
# because two libraries should not go to the same destination.
raise ValueError(f"{absolute_library_path} already exists.")
libraries[absolute_library_path] = library
# remove existing .repo-metadata.json
json_name = ".repo-metadata.json"
Expand Down
Loading