From 5d84bb946f03a84984636d737c5de6b6a2c6c600 Mon Sep 17 00:00:00 2001 From: Brian Moore Date: Wed, 6 Apr 2022 16:51:01 -0500 Subject: [PATCH] workaround for #629 (#631) * workaround for 629 * fix unit tests * fix unit tests --- ...Be-Present-In-Template-Parameters.test.ps1 | 19 ++++++++++++++++++- .../type-mismatch-bool/azureDeploy.json | 0 .../createUiDefinition.json | 1 + .../type-mismatch-int/azureDeploy.json | 0 .../type-mismatch-int/createUiDefinition.json | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) rename unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/{Fail => Pass}/type-mismatch-bool/azureDeploy.json (100%) rename unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/{Fail => Pass}/type-mismatch-bool/createUiDefinition.json (96%) rename unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/{Fail => Pass}/type-mismatch-int/azureDeploy.json (100%) rename unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/{Fail => Pass}/type-mismatch-int/createUiDefinition.json (96%) diff --git a/arm-ttk/testcases/CreateUIDefinition/Outputs-Must-Be-Present-In-Template-Parameters.test.ps1 b/arm-ttk/testcases/CreateUIDefinition/Outputs-Must-Be-Present-In-Template-Parameters.test.ps1 index f74cb32c..cf2ac6b2 100644 --- a/arm-ttk/testcases/CreateUIDefinition/Outputs-Must-Be-Present-In-Template-Parameters.test.ps1 +++ b/arm-ttk/testcases/CreateUIDefinition/Outputs-Must-Be-Present-In-Template-Parameters.test.ps1 @@ -37,7 +37,7 @@ $IsInnerTemplate, [Collections.IDictionary] $AllowedFunctionInOutput = $(@{ int = 'int', 'min', 'max', 'div', 'add', 'mod', 'mul', 'sub', 'copyIndex','length', 'coalesce' - bool = 'equals', 'less', 'lessOrEquals', 'greater', 'greaterOrEquals', 'and', 'or','not', 'true', 'false', 'contains','empty','coalesce','if' + bool = 'bool', 'equals', 'less', 'lessOrEquals', 'greater', 'greaterOrEquals', 'and', 'or','not', 'true', 'false', 'contains','empty','coalesce','if' }) ) @@ -68,6 +68,22 @@ foreach ($output in $parameterInfo.outputs.psobject.properties) { # Then walk th Write-Error "output $outputName does not exist in template.parameters" -ErrorId CreateUIDefinition.Output.Missing.From.MainTemplate -TargetObject $parameterInfo.outputs } + # check that the type of the output matches the type declared in the template, note that the output type may be set on the control itself through the same expression +<# + + TODO: + Removing the test for now... there are some controls in CUID that allow setting the value explicitly + For these controls we need to check that value property for the allowed functions or type + Some of these controls are arrays of values, so we would have to look at each array element for the allowedFunctions + Cases to consider: + - Checkbox control already returns a bool + - DropDown control - array of objects that contain a value property + - OptionsGroup - array of objects that contain a value property + - slider - returns an int + + Note that these controls can be complex and nested and if the output value does not comply, only then do we need to check the control value for the output + With coalescing, this can be tricky. + $outputParameterType = $TemplateObject.parameters.$outputName.type if ($outputParameterType -and $outputParameterType -ne 'string') { $firstOutputFunction = $output.Value | ? -Extract | Select-Object -ExpandProperty FunctionName @@ -79,4 +95,5 @@ foreach ($output in $parameterInfo.outputs.psobject.properties) { # Then walk th } } } +#> } diff --git a/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-bool/azureDeploy.json b/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-bool/azureDeploy.json similarity index 100% rename from unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-bool/azureDeploy.json rename to unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-bool/azureDeploy.json diff --git a/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-bool/createUiDefinition.json b/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-bool/createUiDefinition.json similarity index 96% rename from unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-bool/createUiDefinition.json rename to unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-bool/createUiDefinition.json index f1170dac..11c11fa3 100644 --- a/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-bool/createUiDefinition.json +++ b/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-bool/createUiDefinition.json @@ -46,6 +46,7 @@ ] } ], + // TODO: move this test back to FAIL folder when #629 is properly fixed "outputs": { "location": "[location()]", "testBoolean": "[int('1')]" diff --git a/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-int/azureDeploy.json b/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-int/azureDeploy.json similarity index 100% rename from unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-int/azureDeploy.json rename to unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-int/azureDeploy.json diff --git a/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-int/createUiDefinition.json b/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-int/createUiDefinition.json similarity index 96% rename from unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-int/createUiDefinition.json rename to unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-int/createUiDefinition.json index de90e307..0bbbb148 100644 --- a/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Fail/type-mismatch-int/createUiDefinition.json +++ b/unit-tests/Outputs-Must-Be-Present-In-Template-Parameters/Pass/type-mismatch-int/createUiDefinition.json @@ -47,6 +47,7 @@ } ], "outputs": { + // TODO: move this test back to FAIL folder when #629 is properly fixed "location": "[location()]", "swarmRootDiskSize": "[steps('SwarmConfig').vmSettings.rootDiskSize]" }