Testfall för createUiDefinition.json
Den här artikeln beskriver de tester som körs med malltestverktyget för createUiDefinition.json-filer . Exemplen innehåller testnamn och kodexempel som klarar eller misslyckas med testerna.
Verktygslådan innehåller testfall för Azure Resource Manager-mallar (ARM-mallar) och huvudmallfilerna med namnet azuredeploy.json eller maintemplate.json. När katalogen innehåller en createUiDefinition.json-fil körs specifika tester för användargränssnittskontroller. Mer information om hur du kör tester eller hur du kör ett visst test finns i Testparametrar.
Filen createUiDefinition.json skapar anpassade användargränssnittskontroller (UI) med hjälp av element och funktioner.
Verifiera att mallparametern tillåter värden
Testnamn: Tillåtna värden bör faktiskt tillåtas
Det här testet kontrollerar att värden för varje kontroll i createUiDefinition.json tillåts i huvudmallens parametrar. Parametrarna mappas efter namn mellan huvudmallen och filen createUiDefinition.json .
Huvudmallens parameter måste acceptera värdena från kontrollens allowedValues
. Testet kontrollerar också att kontrollen refereras till i avsnittet createUiDefinition.jsonoutputs
.
Det här testet kontrollerar huvudmallen och filen createUiDefinition.json . Ett exempel på filen createUiDefinition.json visas efter huvudmallsexemplen.
Följande exempel misslyckas eftersom huvudmallens parameternamn combo
inte matchar kontrollens parameternamn comboBox
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"combo": {
"type": "string",
"defaultValue": "two"
}
},
"resources": [],
"outputs": {
"comboBoxOutput": {
"type": "string",
"value": "[parameters('combo')]"
}
}
}
Följande exempel misslyckas eftersom huvudmallens parametertyp int
inte accepterar kontrollens string
värde. Och om en huvudmalls parameter definierar en defaultValue
måste den vara giltig value
i kontrollens allowedValues
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"comboBox": {
"type": "int",
"defaultValue": 4
}
},
"resources": [],
"outputs": {
"comboBoxOutput": {
"type": "string",
"value": "[parameters('combo')]"
}
}
}
Följande exempel godkänns eftersom huvudmallens parameternamn matchar kontrollens parameternamn. Och mallens parametertyp är en string
med en defaultValue
som anges i kontrollens allowedValues
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"comboBox": {
"type": "string",
"defaultValue": "two"
}
},
"resources": [],
"outputs": {
"comboBoxOutput": {
"type": "string",
"value": "[parameters('comboBox')]"
}
}
}
Filen createUiDefinition.json för det här exemplet:
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [],
"steps": [
{
"name": "demoComboBox",
"label": "demoComboBoxLabel",
"elements": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"defaultValue": "Value two",
"toolTip": "This is a tool tip",
"constraints": {
"allowedValues": [
{
"label": "Value one",
"description": "The value to select for option 1.",
"value": "one"
},
{
"label": "Value two",
"description": "The value to select for option 2.",
"value": "two"
}
],
"required": true
},
"visible": true
}
]
}
],
"outputs": {
"comboBox": "[steps('demoComboBox').comboBox]"
}
}
}
Utdatakontroller måste finnas
Testnamn: Kontroller i utdata måste finnas
Kontroller som används i outputs
avsnittet måste finnas i ett element någon annanstans i createUiDefinition.json. Namnet som refereras i outputs
måste matcha ett namn som används i basics[]
eller steps[]
.
Följande exempel misslyckas.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "nameDoesNotMatchOutput",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]"
}
}
}
Egenskaper måste innehålla värden
Testnamn: CreateUIDefinition får inte ha tomma värden
Egenskaper måste innehålla värden. Nödvändiga egenskaper måste använda giltiga värden. Valfria egenskaper som är tomma bör tas bort. Testet tillåter blank "basics": []
, "steps": []
eller defaultValue
.
Följande exempel misslyckas eftersom label
, placeholder
och toolTip
är tomma.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "",
"placeholder": "",
"defaultValue": "",
"toolTip": ""
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]"
}
}
}
Följande exempel skickas eftersom label
och toolTip
har värden och placeholder
har tagits bort.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"defaultValue": "",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]"
}
}
}
Använda giltigt schema och version
Testnamn: CreateUIDefinition bör ha schema
Filen createUiDefinition.json måste innehålla en $schema
egenskap och använda en giltig $schema
och version
. Versionsnumren i $schema
och version
måste matcha.
Följande exempel misslyckas.
{
"$schema": "https://schema.management.azure.com/schemas/0.9.9-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.9.9-preview"
}
Följande exempel godkänns eftersom det använder den senaste $schema
och version
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview"
}
Dölj inte bekräftelse av autentiseringsuppgifter
Testnamn: Bekräftelse av autentiseringsuppgifter bör inte döljas
Det här testet kontrollerar att autentiseringsuppgifterna har bekräftats för Microsoft.Common.PasswordBox eller Microsoft.Compute.CredentialsCombo. Egenskapen hideConfirmation
ska anges till false
så att bekräftelsen visas.
Följande exempel misslyckas eftersom hideConfirmation
är true
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "credentials",
"type": "Microsoft.Compute.CredentialsCombo",
"label": {
"password": "Password",
"confirmPassword": "Confirm password"
},
"toolTip": {
"password": "Type your credentials"
},
"constraints": {
"required": true,
"customPasswordRegex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{12,}$",
"customValidationMessage": "The password must be alphanumeric, contain at least 12 characters, and have at least 1 letter and 1 number."
},
"options": {
"hideConfirmation": true
},
"osPlatform": "Windows",
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"credentials": "[basics('credentials')]"
}
}
}
Följande exempel godkänns eftersom hideConfirmation
är false
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "credentials",
"type": "Microsoft.Compute.CredentialsCombo",
"label": {
"password": "Password",
"confirmPassword": "Confirm password"
},
"toolTip": {
"password": "Type your credentials"
},
"constraints": {
"required": true,
"customPasswordRegex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{12,}$",
"customValidationMessage": "The password must be alphanumeric, contain at least 12 characters, and have at least 1 letter and 1 number."
},
"options": {
"hideConfirmation": false
},
"osPlatform": "Windows",
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"credentials": "[basics('credentials')]"
}
}
}
Använd rätt hanterare
Testnamn: Hanteraren måste vara korrekt
Använd Microsoft.Azure.CreateUIDef
eller Microsoft.Compute.MultiVm
i filen createUiDefinition.json .
Följande exempel misslyckas.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.",
"version": "0.1.2-preview"
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview"
}
Dölj inte befintliga resurser
Testnamn: HideExisting måste hanteras korrekt
Om hideExisting
anges till false
eller utelämnas outputs
måste innehålla resourceGroup
och newOrExisting
. Standardvärdet för hideExisting
är false
.
Exempel på kontrolltyper som inkluderar hideExisting
är Microsoft.Storage.StorageAccountSelector, Microsoft.Network.PublicIpAddressCombo eller Microsoft.Network.VirtualNetworkCombo.
Följande exempel misslyckas.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "storage",
"type": "Microsoft.Storage.StorageAccountSelector",
"label": "Storage account",
"toolTip": "This is a demo storage account",
"defaultValue": {
"name": "storageaccount01",
"type": "Premium_LRS"
},
"options": {
"hideExisting": false
},
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "storage",
"type": "Microsoft.Storage.StorageAccountSelector",
"label": "Storage account",
"toolTip": "This is a demo storage account",
"defaultValue": {
"name": "storageaccount01",
"type": "Premium_LRS"
},
"options": {
"hideExisting": false
},
"visible": false
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"resourceGroup": "[basics('storage').resourceGroup]",
"newOrExisting": "[basics('storage').newOrExisting]"
}
}
}
Använd plats i utdata
Testnamn: Platsen ska finnas i utdata
Avsnittet outputs
ska innehålla en plats med hjälp av platsfunktionen .
Följande exempel misslyckas eftersom outputs
inte innehåller någon plats.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]",
"location": "[location()]"
}
}
}
Inkludera kontrollutdata i mallparametrar
Testnamn: Utdata måste finnas i mallparametrar
Testet kontrollerar att createUiDefinition.json innehåller ett outputs
avsnitt. Testet kontrollerar också att dessa outputs
definieras i huvudmallens parameters
avsnitt. Namnen måste matcha eftersom parametrarna mappas efter namn mellan createUiDefinition.json och huvudmallen.
Det här testet kontrollerar huvudmallen och filen createUiDefinition.json . Ett exempel på filen createUiDefinition.json visas efter huvudmallsexemplen.
Följande exempel misslyckas eftersom huvudmallen inte innehåller parametern comboBox
från avsnittet createUiDefinition.jsonoutputs
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
}
}
}
Följande exempel skickas eftersom huvudmallen innehåller parametern comboBox
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"comboBox": {
"type": "string",
"defaultValue": "two"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [],
"outputs": {
"comboBox": {
"type": "string",
"value": "[parameters('comboBox')]"
},
"location": {
"type": "string",
"value": "[parameters('location')]"
}
}
}
Filen createUiDefinition.json för det här exemplet:
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]",
"location": "[location()]"
}
}
}
Parametrar utan standard måste finnas i utdata
Testnamn: Parametrar utan standard måste finnas i CreateUIDefinition
Parametrar i huvudmallen utan standardvärde måste finnas i avsnittet createUiDefinition.json-filenoutputs
.
Det här testet kontrollerar huvudmallen och filen createUiDefinition.json . Ett exempel på filen azuredeploy.json visas efter kontrollens exempel.
Följande exempel misslyckas eftersom filen outputs
createUiDefinition.json inte innehåller huvudmallens parameter comboBox
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"location": "[location()]"
}
}
}
Följande exempel godkänns eftersom createUiDefinition.json innehåller comboBox
i outputs
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"comboBox": "[basics('comboBox')]",
"location": "[location()]"
}
}
}
Filen azuredeploy.json för det här exemplet. Parametern comboBox
har inget standardvärde.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"comboBox": {
"type": "string"
},
"location": {
"type": "string"
}
},
"resources": [],
"outputs": {
"comboBox": {
"type": "string",
"value": "[parameters('comboBox')]"
},
"location": {
"type": "string",
"value": "[parameters('location')]"
}
}
}
Använda säker parameter med lösenordsruta
Testnamn: Textrutor för lösenord måste användas för lösenordsparametrar
Det här testet kontrollerar att ett Microsoft.Common.PasswordBox-element har definierats i huvudmallens parameters
och createUiDefinition.jsonoutputs
. Huvudmallens parametertyp för en lösenordsruta måste vara secureString
eller secureObject
.
Det här testet kontrollerar huvudmallen och filen createUiDefinition.json . Ett exempel på filen createUiDefinition.json visas efter huvudmallsexemplen.
Följande exempel misslyckas eftersom huvudmallens passwordBox
parameter är en string
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"passwordBox": {
"type": "string"
},
"location": {
"type": "string"
}
},
"resources": [],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
}
}
}
Följande exempel godkänns eftersom huvudmallens passwordBox
parameter är en secureString
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"passwordBox": {
"type": "secureString"
},
"location": {
"type": "string"
}
},
"resources": [],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
}
}
}
Filen createUiDefinition.json för det här exemplet:
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "passwordBox",
"type": "Microsoft.Common.PasswordBox",
"label": {
"password": "Password",
"confirmPassword": "Confirm password"
},
"toolTip": "Type a password"
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"passwordBox": "[basics('passwordBox')]"
}
}
}
Lösenordsrutan kräver minsta längd
Testnamn: PasswordBoxes måste ha minsta längd
Testet kontrollerar att elementet Microsoft.Common.PasswordBox använder constraints
med ett regex
som kräver minst 12 tecken.
Följande exempel misslyckas eftersom det inte finns några constraints
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "passwordBox",
"type": "Microsoft.Common.PasswordBox",
"label": {
"password": "Password",
"confirmPassword": "Confirm password"
},
"toolTip": "Type a password"
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"passwordBox": "[basics('passwordBox')]"
}
}
}
Följande exempel godkänns eftersom kräver regex
minst 12 tecken.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "passwordBox",
"type": "Microsoft.Common.PasswordBox",
"label": {
"password": "Password",
"confirmPassword": "Confirm password"
},
"toolTip": "Type a password",
"constraints": {
"required": true,
"regex": "^[a-zA-Z0-9]{12,}$",
"validationMessage": "Password must be at least 12 characters long, contain only numbers and letters"
}
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"passwordBox": "[basics('passwordBox')]"
}
}
}
Textrutan måste använda validering
Testnamn: Textrutorna är välformade
Använd validering med textrutor för constraints
att söka efter som innehåller en regex
och message
.
Följande exempel misslyckas.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "textBox",
"type": "Microsoft.Common.TextBox",
"label": "Text box",
"toolTip": "Type 1-30 alphanumeric characters",
"placeholder": "Type your text here",
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"textBox": "[basics('textBox')]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "textBox",
"type": "Microsoft.Common.TextBox",
"label": "Text box",
"toolTip": "Type 1-30 alphanumeric characters",
"placeholder": "Type your text here",
"constraints": {
"required": true,
"validations": [
{
"regex": "^[a-z0-9A-Z]{1,30}$",
"message": "Only 1-30 characters alphanumeric characters are allowed."
}
]
},
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"textBox": "[basics('textBox')]"
}
}
}
toolTip måste finnas med ett värde
Testnamn: Knappbeskrivningar ska finnas
Det här testet kontrollerar att egenskapen toolTip
finns och innehåller ett värde.
Följande exempel misslyckas.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": ""
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"comboBox": "[basics('comboBox')]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "comboBox",
"type": "Microsoft.Common.DropDown",
"label": "Example drop down",
"toolTip": "This is a tool tip"
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"comboBox": "[basics('comboBox')]"
}
}
}
Ange inte ett standardanvändarnamn
Testnamn: Användarnamn bör inte ha en standard
Testet kontrollerar om det finns en defaultValue
uppsättning för Microsoft.Compute.UserNameTextBox.
Följande exempel misslyckas eftersom en defaultValue
tillhandahålls.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "userNameBox",
"type": "Microsoft.Compute.UserNameTextBox",
"label": "User name",
"defaultValue": "admin",
"toolTip": "Enter your user name",
"osPlatform": "Windows"
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"userNameBox": "[basics('userNameBox')]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "userNameBox",
"type": "Microsoft.Compute.UserNameTextBox",
"label": "User name",
"toolTip": "Enter your user name",
"osPlatform": "Windows"
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"userNameBox": "[basics('userNameBox')]"
}
}
}
Använda meddelande med valideringar
Testnamn: Verifieringar måste ha meddelande
Det här testet kontrollerar att alla validations
i createUiDefinition.json innehåller en message
.
Följande exempel misslyckas eftersom verifieringen regex
inte har en message
.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "textBox",
"type": "Microsoft.Common.TextBox",
"label": "Text box",
"toolTip": "Type 1-30 alphanumeric characters",
"placeholder": "Type your text here",
"constraints": {
"required": true,
"validations": [
{
"regex": "^[a-z0-9A-Z]{1,30}$"
}
]
},
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"textBox": "[basics('textBox')]"
}
}
}
Följande exempel godkänns.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "textBox",
"type": "Microsoft.Common.TextBox",
"label": "Text box",
"toolTip": "Type 1-30 alphanumeric characters",
"placeholder": "Type your text here",
"constraints": {
"required": true,
"validations": [
{
"regex": "^[a-z0-9A-Z]{1,30}$",
"message": "Only 1-30 characters alphanumeric characters are allowed."
}
]
},
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"textBox": "[basics('textBox')]"
}
}
}
Storlekar på virtuella datorer måste matcha
Testnamn: VM-storlekar måste matcha mallen
Det här testet kontrollerar att Microsoft.Compute.SizeSelector finns i avsnittet createUiDefinition.jsonoutputs
och huvudmallen parameters
. Huvudmallsparametrar som anger ett defaultValue
måste matcha ett värde i kontrollens allowedSizes
.
Det här testet kontrollerar huvudmallen och filen createUiDefinition.json . Ett exempel på filen createUiDefinition.json visas efter huvudmallsexemplen.
Följande exempel misslyckas eftersom huvudmallens defaultValue
inte matchar ett värde i allowedSizes
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D9"
}
},
"resources": [],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
},
"vmSize": {
"type": "string",
"value": "[parameters('vmSize')]"
}
}
}
Följande exempel godkänns eftersom huvudmallens defaultValue
matchar ett värde i allowedSizes
.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D3"
}
},
"resources": [],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
},
"vmSize": {
"type": "string",
"value": "[parameters('vmSize')]"
}
}
}
Filen createUiDefinition.json för det här exemplet:
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "vmSize",
"type": "Microsoft.Compute.SizeSelector",
"label": "VM Size",
"toolTip": "Select a virtual machine size",
"recommendedSizes": [
"Standard_D1"
],
"constraints": {
"allowedSizes": [
"Standard_D1",
"Standard_D2",
"Standard_D3"
]
},
"osPlatform": "Windows",
"visible": true
}
],
"steps": [],
"outputs": {
"location": "[location()]",
"vmSize": "[basics('vmSize')]"
}
}
}
Nästa steg
- Information om hur du skapar ett Azure Portal användargränssnitt finns i SkapaUiDefinition.json för azure-hanterade program.
- Information om hur du använder sandbox-miljön Skapa användargränssnittsdefinition finns i Testa portalgränssnittet för Azure Managed Applications.
- Mer information om UI-kontroller finns i CreateUiDefinition-element och CreateUiDefinition-funktioner.
- Mer information om ARM-malltester finns i Testfall för ARM-mallar.