Skip to content

Commit c8c54f8

Browse files
authored
On branch master: add inner template test case for Outputs-Must-Be-Present-In-Template-Parameters (#535)
* On branch master: add unittest case for inner template built by bicep. Signed-off-by: galiacheng <[email protected]> Changes to be committed: modified: arm-ttk/Test-AzTemplate.ps1 modified: arm-ttk/testcases/CreateUIDefinition/Outputs-Must-Be-Present-In-Template-Parameters.test.ps1 new file: unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/InnerTemplate/azuredeploy.json new file: unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/InnerTemplate/createUiDefinition.json * On branch master: do not output the object info Signed-off-by: galiacheng <[email protected]> Changes to be committed: modified: arm-ttk/Test-AzTemplate.ps1
1 parent 23f9d5b commit c8c54f8

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed

arm-ttk/Test-AzTemplate.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Test-AzTemplate
1+
function Test-AzTemplate
22
{
33
[Alias('Test-AzureRMTemplate')] # Added for backward compat with MP
44
<#
@@ -33,7 +33,6 @@ Each test script has access to a set of well-known variables:
3333
* InnerTemplates (indicates if the template contained or was in inner templates)
3434
* ExpandedTemplateText (the text of a template, with variables expanded)
3535
* ExpandedTemplateOjbect (the object of a template, with variables expanded)
36-
* InnerTemplates (indicates if the template contained or was in inner templates
3736
3837
.Example
3938
Test-AzTemplate -TemplatePath ./FolderWithATemplate
@@ -265,6 +264,7 @@ Each test script has access to a set of well-known variables:
265264
# And Map TemplateObject to the converted json (if the test command uses -TemplateObject)
266265
if ($testCommandParameters.ContainsKey("TemplateObject")) {
267266
$templateObject = $testInput['TemplateObject'] = $innerTemplate.template
267+
$templateObject | Add-Member NoteProperty IsInnerTemplate $true -Force
268268
$usedParameters = $true
269269
}
270270

arm-ttk/testcases/CreateUIDefinition/Outputs-Must-Be-Present-In-Template-Parameters.test.ps1

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.Synopsis
33
Ensures that .outputs are present in the .parameters of CreateUIDefinition.json
44
.Description
@@ -35,7 +35,13 @@ foreach ($output in $parameterInfo.outputs.psobject.properties) { # Then walk th
3535
$outputName -eq 'managedresourcegroupid') { # If the output was one of the outputs used for Managed Apps and only found in the generated template, skip the test
3636
continue
3737
}
38-
# If the output name was not declared in the TemplateObject,
38+
39+
# If the TemplateObject is inner template of MainTemplate, skip the test
40+
if ($TemplateObject.IsInnerTemplate){
41+
continue
42+
}
43+
44+
# If the output name was not declared in the TemplateObject
3945
if (-not $TemplateObject.parameters.$outputName) {
4046
# write an error
4147
Write-Error "output $outputName does not exist in template.parameters" -ErrorId CreateUIDefinition.Output.Missing.From.MainTemplate -TargetObject $parameterInfo.outputs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"location": {
6+
"type": "string",
7+
"defaultValue": "[resourceGroup().location]",
8+
"metadata": {
9+
"description": "Location for all resources."
10+
}
11+
},
12+
"MyOutput": {
13+
"type": "string",
14+
"defaultValue": "test",
15+
"metadata": {
16+
"description": "Test output."
17+
}
18+
}
19+
},
20+
"variables": {
21+
},
22+
"resources": [
23+
{
24+
"type": "Microsoft.Resources/deployments",
25+
"apiVersion": "2019-10-01",
26+
"name": "initialization",
27+
"properties": {
28+
"expressionEvaluationOptions": {
29+
"scope": "inner"
30+
},
31+
"mode": "Incremental",
32+
"template": {
33+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
34+
"contentVersion": "1.0.0.0",
35+
"metadata": {
36+
"_generator": {
37+
"name": "bicep",
38+
"version": "0.4.451.19169",
39+
"templateHash": "10244511904155871293"
40+
}
41+
},
42+
"parameters": {
43+
"name": {
44+
"type": "string",
45+
"defaultValue": "pid"
46+
}
47+
},
48+
"functions": [],
49+
"resources": [
50+
],
51+
"outputs": {
52+
"name": {
53+
"type": "string",
54+
"value": "[parameters('name')]"
55+
}
56+
}
57+
}
58+
}
59+
}
60+
],
61+
"outputs": {
62+
"location": {
63+
"type": "string",
64+
"value": "[parameters('location')]"
65+
},
66+
"MyOutput": {
67+
"type": "string",
68+
"value": "[parameters('MyOutput')]"
69+
}
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
3+
"handler": "Microsoft.Azure.CreateUIDef",
4+
"version": "0.1.2-preview",
5+
"parameters": {
6+
"basics": [
7+
{
8+
"name": "TextBox1",
9+
"type": "Microsoft.Common.TextBox",
10+
"label": "Textboxes With Invalid Regex",
11+
"toolTip": "Textboxes with invalid regex.",
12+
"constraints": {
13+
"required": true,
14+
"regex": "^[1-9]$",
15+
"validationMessage": "Textboxes with invalid regex in constraints.regex."
16+
}
17+
}
18+
],
19+
"outputs": {
20+
"Location": "[location()]",
21+
"MyOutput": "foo"
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)