Skip to content

Commit 2aa4291

Browse files
Copilota0x1ab
andauthored
[Resource] Cover generated snapshot deployment names
Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
1 parent c6946b0 commit 2aa4291

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/azure-cli/azure/cli/command_modules/resource/custom.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262

6363
logger = get_logger(__name__)
6464

65+
_CLI_GENERATED_DEPLOYMENT_NAME_PATTERN = re.compile(r'azurecli\d+\.\d+')
66+
6567
RPAAS_APIS = {'microsoft.datadog': '/subscriptions/{subscriptionId}/providers/Microsoft.Datadog/agreements/default?api-version=2020-02-01-preview',
6668
'microsoft.confluent': '/subscriptions/{subscriptionId}/providers/Microsoft.Confluent/agreements/default?api-version=2020-03-01-preview'}
6769

@@ -4651,7 +4653,7 @@ def snapshot_bicep_file(cmd, file, mode=None, tenant_id=None, subscription_id=No
46514653
args += ["--location", location]
46524654
if resource_group:
46534655
args += ["--resource-group", resource_group]
4654-
if deployment_name and not re.fullmatch(r'azurecli\d+\.\d+', deployment_name):
4656+
if deployment_name and not _CLI_GENERATED_DEPLOYMENT_NAME_PATTERN.fullmatch(deployment_name):
46554657
args += ["--deployment-name", deployment_name]
46564658

46574659
output = run_bicep_command(cmd.cli_ctx, args)

‎src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ def test_snapshot_bicep_file_ignores_generated_deployment_name(
343343

344344
run_bicep_command_mock.assert_called_once_with(self.cli_ctx, ["snapshot", "main.bicepparam"])
345345

346+
@mock.patch("azure.cli.command_modules.resource.custom.run_bicep_command")
347+
@mock.patch("azure.cli.command_modules.resource.custom.bicep_version_greater_than_or_equal_to")
348+
@mock.patch("azure.cli.command_modules.resource.custom.ensure_bicep_installation")
349+
def test_snapshot_bicep_file_passes_similarly_named_deployment_name(
350+
self, ensure_bicep_installation_mock, bicep_version_check_mock, run_bicep_command_mock
351+
):
352+
bicep_version_check_mock.return_value = True
353+
run_bicep_command_mock.return_value = ""
354+
355+
snapshot_bicep_file(self.cmd, "main.bicepparam", deployment_name="azurecli123")
356+
357+
run_bicep_command_mock.assert_called_once_with(
358+
self.cli_ctx, ["snapshot", "main.bicepparam", "--deployment-name", "azurecli123"]
359+
)
360+
346361
@mock.patch("azure.cli.command_modules.resource.custom.run_bicep_command")
347362
@mock.patch("azure.cli.command_modules.resource.custom.bicep_version_greater_than_or_equal_to")
348363
@mock.patch("azure.cli.command_modules.resource.custom.ensure_bicep_installation")

0 commit comments

Comments
 (0)