Skip to content

Commit bc98e21

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "tests: Simplify catalog functional tests"
2 parents 475d69e + 68d1d01 commit bc98e21

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

openstackclient/tests/functional/identity/v3/test_catalog.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,54 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
1314
from openstackclient.tests.functional.identity.v3 import common
1415

1516

1617
class CatalogTests(common.IdentityTests):
17-
def test_catalog_list(self):
18+
"""Functional tests for catalog commands"""
19+
20+
def test_catalog(self):
21+
"""Test catalog list and show functionality"""
22+
# Create a test service for isolated testing
23+
_dummy_service_name = self._create_dummy_service(add_clean_up=True)
24+
25+
# list catalogs
1826
raw_output = self.openstack('catalog list')
1927
items = self.parse_listing(raw_output)
2028
self.assert_table_structure(items, ['Name', 'Type', 'Endpoints'])
2129

22-
def test_catalog_show(self):
23-
"""test catalog show command
24-
25-
The output example:
26-
+-----------+----------------------------------------+
27-
| Field | Value |
28-
+-----------+----------------------------------------+
29-
| endpoints | test1 |
30-
| | public: http://localhost:5000/v2.0 |
31-
| | test1 |
32-
| | internal: http://localhost:5000/v2.0 |
33-
| | test1 |
34-
| | admin: http://localhost:35357/v2.0 |
35-
| | |
36-
| id | e1e68b5ba21a43a39ff1cf58e736c3aa |
37-
| name | keystone |
38-
| type | identity |
39-
+-----------+----------------------------------------+
40-
"""
41-
raw_output = self.openstack('catalog show {}'.format('identity'))
30+
# Verify created service appears in catalog
31+
service_names = [
32+
item.get('Name') for item in items if item.get('Name')
33+
]
34+
self.assertIn(
35+
_dummy_service_name,
36+
service_names,
37+
"Created dummy service should be present in catalog",
38+
)
39+
40+
# show service (by name)
41+
raw_output = self.openstack(f'catalog show {_dummy_service_name}')
4242
items = self.parse_show(raw_output)
43-
# items may have multiple endpoint urls with empty key
44-
self.assert_show_fields(items, ['endpoints', 'name', 'type', '', 'id'])
43+
self.assert_show_fields(items, ['endpoints', 'name', 'type', 'id'])
44+
45+
# Extract the type from the dummy service
46+
_dummy_service_type = next(
47+
(item['type'] for item in items if 'type' in item), None
48+
)
49+
50+
# show service (by type)
51+
raw_output = self.openstack(f'catalog show {_dummy_service_type}')
52+
items = self.parse_show(raw_output)
53+
self.assert_show_fields(items, ['endpoints', 'name', 'type', 'id'])
54+
55+
# show service (non-existent)
56+
result = self.openstack(
57+
'catalog show nonexistent-service-xyz', fail_ok=True
58+
)
59+
self.assertEqual(
60+
'',
61+
result.strip(),
62+
"Non-existent service should return empty result",
63+
)

0 commit comments

Comments
 (0)