|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import unittest |
| 15 | + |
| 16 | +from library_generation.model.gapic_config import GapicConfig |
| 17 | + |
| 18 | + |
| 19 | +class GapicConfigTest(unittest.TestCase): |
| 20 | + def test_get_version_returns_none(self): |
| 21 | + self.assertIsNone(GapicConfig(proto_path="example/dir1/dir2").get_version()) |
| 22 | + |
| 23 | + def test_get_version_returns_non_stable_version(self): |
| 24 | + self.assertEqual( |
| 25 | + "v2p2beta1", |
| 26 | + GapicConfig(proto_path="example/dir1/dir2/v2p2beta1").get_version(), |
| 27 | + ) |
| 28 | + self.assertEqual( |
| 29 | + "v2beta1", |
| 30 | + GapicConfig(proto_path="example/dir1/dir2/v2beta1").get_version(), |
| 31 | + ) |
| 32 | + |
| 33 | + def test_get_version_returns_stable_version(self): |
| 34 | + self.assertEqual( |
| 35 | + "v20", |
| 36 | + GapicConfig(proto_path="example/dir1/dir2/v20").get_version(), |
| 37 | + ) |
| 38 | + |
| 39 | + def test_is_stable_with_no_version_returns_false(self): |
| 40 | + self.assertFalse( |
| 41 | + GapicConfig(proto_path="example/dir1/dir2/non_version").is_stable(), |
| 42 | + ) |
| 43 | + |
| 44 | + def test_is_stable_with_non_stable_version_returns_false(self): |
| 45 | + self.assertFalse( |
| 46 | + GapicConfig(proto_path="example/dir1/dir2/v20alpha").is_stable(), |
| 47 | + ) |
| 48 | + self.assertFalse( |
| 49 | + GapicConfig(proto_path="example/dir1/dir2/v20beta2").is_stable(), |
| 50 | + ) |
| 51 | + |
| 52 | + def test_is_stable_with_stable_version_returns_true(self): |
| 53 | + self.assertTrue( |
| 54 | + GapicConfig(proto_path="example/dir1/dir2/v30").is_stable(), |
| 55 | + ) |
| 56 | + |
| 57 | + def test_compare_configs_without_a_version(self): |
| 58 | + config_len_3 = GapicConfig(proto_path="example/dir1/dir2") |
| 59 | + config_len_4 = GapicConfig(proto_path="example/dir1/dir2/dir3") |
| 60 | + self.assertLess( |
| 61 | + config_len_3, |
| 62 | + config_len_4, |
| 63 | + "config_len_3 should be smaller since it has a lower depth.", |
| 64 | + ) |
| 65 | + |
| 66 | + def test_compare_configs_only_one_has_a_stable_version(self): |
| 67 | + versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v1") |
| 68 | + non_versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3") |
| 69 | + self.assertLess( |
| 70 | + versioned_config, |
| 71 | + non_versioned_config, |
| 72 | + "versioned_config should be smaller since it has a version.", |
| 73 | + ) |
| 74 | + |
| 75 | + def test_compare_configs_only_one_has_a_non_stable_version(self): |
| 76 | + non_stable_versioned_config = GapicConfig( |
| 77 | + proto_path="example/dir1/dir2/dir3/dir4/v1beta" |
| 78 | + ) |
| 79 | + non_versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3") |
| 80 | + self.assertLess( |
| 81 | + non_stable_versioned_config, |
| 82 | + non_versioned_config, |
| 83 | + "non_stable_versioned_config should be smaller since it has a version.", |
| 84 | + ) |
| 85 | + |
| 86 | + def test_compare_configs_one_has_non_stable_and_one_has_stable_version(self): |
| 87 | + stable_versioned_config = GapicConfig( |
| 88 | + proto_path="example/dir1/dir2/dir3/dir4/v1" |
| 89 | + ) |
| 90 | + non_stable_versioned_config = GapicConfig(proto_path="example/dir1/dir2/v2beta") |
| 91 | + self.assertLess( |
| 92 | + stable_versioned_config, |
| 93 | + non_stable_versioned_config, |
| 94 | + "stable_versioned_config should be smaller since it has a stable version.", |
| 95 | + ) |
| 96 | + |
| 97 | + def test_compare_configs_two_have_non_stable_version(self): |
| 98 | + v3p2beta = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v3p2beta") |
| 99 | + v2p4beta = GapicConfig(proto_path="example/dir1/dir2/v2p4beta") |
| 100 | + self.assertLess( |
| 101 | + v3p2beta, |
| 102 | + v2p4beta, |
| 103 | + "v3p2beta should be smaller since it has a higher version.", |
| 104 | + ) |
| 105 | + |
| 106 | + def test_compare_configs_two_have_stable_version_different_depth(self): |
| 107 | + v3 = GapicConfig(proto_path="example/dir1/dir2/v3") |
| 108 | + v4 = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v4") |
| 109 | + self.assertLess( |
| 110 | + v3, |
| 111 | + v4, |
| 112 | + "v3 should be smaller since it has lower depth", |
| 113 | + ) |
| 114 | + |
| 115 | + def test_compare_configs_two_have_stable_version_same_depth(self): |
| 116 | + v4 = GapicConfig(proto_path="example/dir1/dir2/v4") |
| 117 | + v3 = GapicConfig(proto_path="example/dir1/dir2/v3") |
| 118 | + self.assertLess( |
| 119 | + v4, |
| 120 | + v3, |
| 121 | + "v4 should be smaller since it has a higher version", |
| 122 | + ) |
0 commit comments