-
Notifications
You must be signed in to change notification settings - Fork 53
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: populate .repo-metadata.json
from highest version
#2890
Merged
JoeWang1127
merged 6 commits into
main
from
feat/populate-metadate-from-highest-version
Jun 19, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57f1a13
feat: populate ``.repo-metadata.json` using the highest version
JoeWang1127 bd77781
add unit tests
JoeWang1127 aaf65a9
Merge branch 'main' into feat/populate-metadate-from-highest-version
JoeWang1127 07f5172
Merge branch 'main' into feat/populate-metadate-from-highest-version
JoeWang1127 b9611ff
change comparsion alg
JoeWang1127 c2e7b1c
add unit tests
JoeWang1127 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
library_generation/test/model/gapic_config_unit_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import unittest | ||
|
||
from library_generation.model.gapic_config import GapicConfig | ||
|
||
|
||
class GapicConfigTest(unittest.TestCase): | ||
def test_get_version_returns_none(self): | ||
self.assertIsNone(GapicConfig(proto_path="example/dir1/dir2").get_version()) | ||
|
||
def test_get_version_returns_non_stable_version(self): | ||
self.assertEqual( | ||
"v2p2beta1", | ||
GapicConfig(proto_path="example/dir1/dir2/v2p2beta1").get_version(), | ||
) | ||
self.assertEqual( | ||
"v2beta1", | ||
GapicConfig(proto_path="example/dir1/dir2/v2beta1").get_version(), | ||
) | ||
|
||
def test_get_version_returns_stable_version(self): | ||
self.assertEqual( | ||
"v20", | ||
GapicConfig(proto_path="example/dir1/dir2/v20").get_version(), | ||
) | ||
|
||
def test_is_stable_with_no_version_returns_false(self): | ||
self.assertFalse( | ||
GapicConfig(proto_path="example/dir1/dir2/non_version").is_stable(), | ||
) | ||
|
||
def test_is_stable_with_non_stable_version_returns_false(self): | ||
self.assertFalse( | ||
GapicConfig(proto_path="example/dir1/dir2/v20alpha").is_stable(), | ||
) | ||
self.assertFalse( | ||
GapicConfig(proto_path="example/dir1/dir2/v20beta2").is_stable(), | ||
) | ||
|
||
def test_is_stable_with_stable_version_returns_true(self): | ||
self.assertTrue( | ||
GapicConfig(proto_path="example/dir1/dir2/v30").is_stable(), | ||
) | ||
|
||
def test_compare_configs_without_a_version(self): | ||
config_len_3 = GapicConfig(proto_path="example/dir1/dir2") | ||
config_len_4 = GapicConfig(proto_path="example/dir1/dir2/dir3") | ||
self.assertLess( | ||
config_len_3, | ||
config_len_4, | ||
"config_len_3 should be smaller since it has a lower depth.", | ||
) | ||
|
||
def test_compare_configs_only_one_has_a_stable_version(self): | ||
versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v1") | ||
non_versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3") | ||
self.assertLess( | ||
versioned_config, | ||
non_versioned_config, | ||
"versioned_config should be smaller since it has a version.", | ||
) | ||
|
||
def test_compare_configs_only_one_has_a_non_stable_version(self): | ||
non_stable_versioned_config = GapicConfig( | ||
proto_path="example/dir1/dir2/dir3/dir4/v1beta" | ||
) | ||
non_versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3") | ||
self.assertLess( | ||
non_stable_versioned_config, | ||
non_versioned_config, | ||
"non_stable_versioned_config should be smaller since it has a version.", | ||
) | ||
|
||
def test_compare_configs_one_has_non_stable_and_one_has_stable_version(self): | ||
stable_versioned_config = GapicConfig( | ||
proto_path="example/dir1/dir2/dir3/dir4/v1" | ||
) | ||
non_stable_versioned_config = GapicConfig(proto_path="example/dir1/dir2/v2beta") | ||
self.assertLess( | ||
stable_versioned_config, | ||
non_stable_versioned_config, | ||
"stable_versioned_config should be smaller since it has a stable version.", | ||
) | ||
|
||
def test_compare_configs_two_have_non_stable_version(self): | ||
v3p2beta = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v3p2beta") | ||
v2p4beta = GapicConfig(proto_path="example/dir1/dir2/v2p4beta") | ||
self.assertLess( | ||
v3p2beta, | ||
v2p4beta, | ||
"v3p2beta should be smaller since it has a higher version.", | ||
) | ||
|
||
def test_compare_configs_two_have_stable_version_different_depth(self): | ||
v3 = GapicConfig(proto_path="example/dir1/dir2/v3") | ||
v4 = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v4") | ||
self.assertLess( | ||
v3, | ||
v4, | ||
"v3 should be smaller since it has lower depth", | ||
) | ||
|
||
def test_compare_configs_two_have_stable_version_same_depth(self): | ||
v4 = GapicConfig(proto_path="example/dir1/dir2/v4") | ||
v3 = GapicConfig(proto_path="example/dir1/dir2/v3") | ||
self.assertLess( | ||
v4, | ||
v3, | ||
"v4 should be smaller since it has a higher version", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a test for each of the scenario? [v1alpha1, v1], [v1, v2] etc. Because
v1alpha1, v1, v2, admin_v2, non_versioned, v1beta1
is sorted tov2, v1, admin_v2, v1beta1, v1alpha1, non_versioned
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added unit tests to verify comparison result of two
gapic_config
s.I kept this test case though.