|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
| 13 | + |
13 | 14 | from openstackclient.tests.functional.identity.v3 import common |
14 | 15 |
|
15 | 16 |
|
16 | 17 | 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 |
18 | 26 | raw_output = self.openstack('catalog list') |
19 | 27 | items = self.parse_listing(raw_output) |
20 | 28 | self.assert_table_structure(items, ['Name', 'Type', 'Endpoints']) |
21 | 29 |
|
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}') |
42 | 42 | 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