From fb613ea6196cd2efced1733b5266653a4122b700 Mon Sep 17 00:00:00 2001 From: Kevin Rowlandson Date: Fri, 3 Jul 2020 12:23:40 +0100 Subject: [PATCH] Test case updates --- .automation/test/arm/arm_bad_1.json | 61 ++++++++++++++++++++++++---- .automation/test/arm/arm_good_1.json | 60 +++++++++++++++++++++++---- TEMPLATES/.arm-ttk.psd1 | 50 +++++++++++------------ lib/linter.sh | 2 +- 4 files changed, 130 insertions(+), 43 deletions(-) diff --git a/.automation/test/arm/arm_bad_1.json b/.automation/test/arm/arm_bad_1.json index 7bb272bd..d75ced62 100644 --- a/.automation/test/arm/arm_bad_1.json +++ b/.automation/test/arm/arm_bad_1.json @@ -1,10 +1,53 @@ { - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "", - "apiProfile": "", - "parameters": { }, - "variables": { }, - "functions": [ ], - "resources": [ ], - "outputs": { } -} + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "", + "parameters": { + "Network.Config": { + "type": "object", + "metadata": { + "description": "Properties object for the Virtual Network" + } + } + }, + "variables": { + "Network.Name": "[parameters('Network.Config').name]", + "Network.Location": "[parameters('Network.Config').location]", + "Network.Tags": "[parameters('Network.Config').tags]", + "Network.Properties.AddressSpace.AddressPrefixes": "[parameters('Network.Config').addressPrefixes]", + "Network.Properties.DhcpOptions.DnsServers": "[parameters('Network.Config').dnsServers]", + "copy": [ + { + "name": "Network.Properties.Subnets", + "count": "[length(parameters('Network.Config').subnetConfig)]", + "input": { + "name": "[concat(parameters('Network.Config').subnetConfig[copyIndex('Network.Properties.Subnets')].aksId,'-',parameters('Network.Config').locationId)]", + "properties": "[parameters('Network.Config').subnetConfig[copyIndex('Network.Properties.Subnets')].properties]" + } + } + ], + "Test.Blank.Variable": [] + }, + "resources": [ + { + "name": "[variables('Network.Name')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2019-12-01", + "tags": "[variables('Network.Tags')]", + "properties": { + "addressSpace": { + "addressPrefixes": "[variables('Network.Properties.AddressSpace.AddressPrefixes')]" + }, + "dhcpOptions": { + "dnsServers": "[variables('Network.Properties.DhcpOptions.DnsServers')]" + }, + "subnets": "[variables('Network.Properties.Subnets')]" + } + } + ], + "outputs": { + "state": { + "type": "object", + "value": "[reference(resourceId('Microsoft.Network/virtualNetworks',variables('Network.Name')), '2019-12-01', 'Full')]" + } + } +} \ No newline at end of file diff --git a/.automation/test/arm/arm_good_1.json b/.automation/test/arm/arm_good_1.json index cf3800de..df09afb7 100644 --- a/.automation/test/arm/arm_good_1.json +++ b/.automation/test/arm/arm_good_1.json @@ -1,9 +1,53 @@ { - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { }, - "variables": { }, - "functions": [ ], - "resources": [ ], - "outputs": { } -} + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "Network.Config": { + "type": "object", + "metadata": { + "description": "Properties object for the Virtual Network" + } + } + }, + "variables": { + "Network.Name": "[parameters('Network.Config').name]", + "Network.Location": "[parameters('Network.Config').location]", + "Network.Tags": "[parameters('Network.Config').tags]", + "Network.Properties.AddressSpace.AddressPrefixes": "[parameters('Network.Config').addressPrefixes]", + "Network.Properties.DhcpOptions.DnsServers": "[parameters('Network.Config').dnsServers]", + "copy": [ + { + "name": "Network.Properties.Subnets", + "count": "[length(parameters('Network.Config').subnetConfig)]", + "input": { + "name": "[concat(parameters('Network.Config').subnetConfig[copyIndex('Network.Properties.Subnets')].aksId,'-',parameters('Network.Config').locationId)]", + "properties": "[parameters('Network.Config').subnetConfig[copyIndex('Network.Properties.Subnets')].properties]" + } + } + ] + }, + "resources": [ + { + "name": "[variables('Network.Name')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2019-12-01", + "location": "[variables('Network.Location')]", + "tags": "[variables('Network.Tags')]", + "properties": { + "addressSpace": { + "addressPrefixes": "[variables('Network.Properties.AddressSpace.AddressPrefixes')]" + }, + "dhcpOptions": { + "dnsServers": "[variables('Network.Properties.DhcpOptions.DnsServers')]" + }, + "subnets": "[variables('Network.Properties.Subnets')]" + } + } + ], + "outputs": { + "state": { + "type": "object", + "value": "[reference(resourceId('Microsoft.Network/virtualNetworks',variables('Network.Name')), '2019-12-01', 'Full')]" + } + } +} \ No newline at end of file diff --git a/TEMPLATES/.arm-ttk.psd1 b/TEMPLATES/.arm-ttk.psd1 index fa4350be..bcddce85 100644 --- a/TEMPLATES/.arm-ttk.psd1 +++ b/TEMPLATES/.arm-ttk.psd1 @@ -2,29 +2,29 @@ # - Test Parameters: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/test-toolkit#test-parameters # - Test Cases: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/test-cases @{ - Test = @( - 'Parameters Property Must Exist', - 'Parameters Must Be Referenced', - 'Secure String Parameters Cannot Have Default', - 'Location Should Not Be Hardcoded', - 'Resources Should Have Location', - 'VM Size Should Be A Parameter', - 'Min And Max Value Are Numbers', - 'artifacts-parameter', - 'Variables Must Be Referenced', - 'Dynamic Variable References Should Not Use Concat', - 'apiVersions Should Be Recent', - 'Providers apiVersions Is Not Permitted', - 'Template Should Not Contain Blanks', - 'IDs Should Be Derived From ResourceIDs', - 'ResourceIds should not contain', - 'DependsOn Must Not Be Conditional', - 'Deployment Resources Must Not Be Debug', - 'adminUsername Should Not Be A Literal', - 'VM Images Should Use Latest Version', - 'Virtual-Machines-Should-Not-Be-Preview', - 'ManagedIdentityExtension must not be used', - 'Outputs Must Not Contain Secrets' - ) - Skip = @() + # Test = @( + # 'Parameters Property Must Exist', + # 'Parameters Must Be Referenced', + # 'Secure String Parameters Cannot Have Default', + # 'Location Should Not Be Hardcoded', + # 'Resources Should Have Location', + # 'VM Size Should Be A Parameter', + # 'Min And Max Value Are Numbers', + # 'artifacts-parameter', + # 'Variables Must Be Referenced', + # 'Dynamic Variable References Should Not Use Concat', + # 'apiVersions Should Be Recent', + # 'Providers apiVersions Is Not Permitted', + # 'Template Should Not Contain Blanks', + # 'IDs Should Be Derived From ResourceIDs', + # 'ResourceIds should not contain', + # 'DependsOn Must Not Be Conditional', + # 'Deployment Resources Must Not Be Debug', + # 'adminUsername Should Not Be A Literal', + # 'VM Images Should Use Latest Version', + # 'Virtual-Machines-Should-Not-Be-Preview', + # 'ManagedIdentityExtension must not be used', + # 'Outputs Must Not Contain Secrets' + # ) + # Skip = @() } diff --git a/lib/linter.sh b/lib/linter.sh index 97f00094..565dae30 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -269,7 +269,7 @@ GetLinterVersions() # Get the version # ################### if [[ "$LINTER" == "arm-ttk" ]]; then - mapfile -t GET_VERSION_CMD < <(cat $ARM_TTK_PSD1 | grep -i version | xargs 2>&1) + mapfile -t GET_VERSION_CMD < <(cat "$ARM_TTK_PSD1" | grep -i version | xargs 2>&1) elif [[ "$LINTER" == "protolint" ]]; then mapfile -t GET_VERSION_CMD < <(echo "--version not supported")