Skip to content

Commit 7acaff9

Browse files
committed
Use synthetic extension names in blocked-load tests
CI agents have the azure-devops extension preinstalled, so the test's assumption that 'az devops' comes from an extension that isn't installed didn't hold there.
1 parent f5795bb commit 7acaff9

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎src/validate/azext_validate/tests/latest/test_validate_metadata.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ def test_bad_cache_file_is_ignored(self):
141141
self.assertEqual(r['status'], 'valid')
142142

143143

144+
# Commands of synthetic extensions that can't be installed anywhere (machines may have real extensions).
145+
_SYNTH = {'module_name': 'azv-synth', 'name': 'azv-synth', 'commands': {'azvsynth query': {
146+
'name': 'azvsynth query', 'parameters': [{'name': 'first', 'options': ['--first'], 'type': 'int'}]}},
147+
'sub_groups': {}}
148+
144149
_PROBE_LOADER = """
145150
from azure.cli.core import AzCommandsLoader
146151
@@ -188,8 +193,11 @@ def load_arguments(self, command):
188193
class _BlockedLoadBase(MetadataTestBase):
189194
"""An installed extension reads a file outside the sandbox while loading, as one preinstalled in some
190195
environments does. Core loads every installed extension for a top-level command it doesn't know."""
191-
responses = _responses(**{_extmeta.INDEX_URL: dict(
192-
_INDEX, devops={'project': {'list': 'azure-devops'}}, azvprobe={'thing': 'azvprobe'})})
196+
responses = _responses(**{
197+
_extmeta.INDEX_URL: dict(_INDEX, azvsynth={'query': 'azv-synth'}, azvmissing={'list': 'azv-missing'},
198+
azvprobe={'thing': 'azvprobe'}),
199+
_EXT_URL + '/ext-azv-synth/version_list.txt': 'az_azv-synth_meta_1.0.0.json\n',
200+
_EXT_URL + '/ext-azv-synth/az_azv-synth_meta_1.0.0.json': _SYNTH})
193201
# Core's own index of installed extensions, as a normal az run would have saved it.
194202
local_index = {'azvprobe': ['azext_azvprobe'], 'validate': ['azext_validate']}
195203
probe_loader = _PROBE_LOADER
@@ -243,7 +251,7 @@ def tearDown(self):
243251

244252
class TestBlockedExtensionLoad(_BlockedLoadBase):
245253
def test_uninstalled_extension_commands_still_checked(self):
246-
code, doc, text = run_validate('--command', "az graph query -q 'x' --first abc", 'az devops project list',
254+
code, doc, text = run_validate('--command', 'az azvsynth query --first abc', 'az azvmissing list',
247255
'az azvprobe thing', 'az vm craete -g rg')
248256
self.assertEqual(code, 0)
249257
got = [(r['status'], ([e['code'] for e in r['errors']] or [r.get('reason', {}).get('code')])[0])
@@ -252,12 +260,12 @@ def test_uninstalled_extension_commands_still_checked(self):
252260
('unchecked', 'ExtensionNotPublished'),
253261
('unchecked', 'InternalError'), # the installed extension that didn't load
254262
('invalid', 'UnknownCommand')]) # core commands don't load extensions
255-
self.assertEqual(doc['results'][0]['source'], 'extension:resource-graph')
263+
self.assertEqual(doc['results'][0]['source'], 'extension:azv-synth')
256264
self.assertNotIn('PROBE-SENTINEL', text)
257265

258266
def test_no_partial_index_saved_or_kept(self):
259267
before = json.dumps(self.extension_index.data, sort_keys=True)
260-
run_validate('--command', 'az devops project list')
268+
run_validate('--command', 'az azvmissing list')
261269
self.assertFalse([n for n in self.saved if n in _INDEX_SESSIONS], self.saved)
262270
self.assertEqual(json.dumps(self.extension_index.data, sort_keys=True), before)
263271

@@ -267,7 +275,7 @@ class TestBlockedExtensionInCoreGroup(_BlockedLoadBase):
267275
local_index = {'vm': ['azext_azvprobe'], 'validate': ['azext_validate']}
268276

269277
def test_later_command_in_same_run(self):
270-
_, doc, _ = run_validate('--command', 'az devops project list', 'az vm azvprobe-cmd')
278+
_, doc, _ = run_validate('--command', 'az azvmissing list', 'az vm azvprobe-cmd')
271279
r = doc['results'][1]
272280
self.assertEqual((r['status'], r['reason']['code']), ('unchecked', 'InternalError'))
273281

0 commit comments

Comments
 (0)