Testfall för alla filer

Den här artikeln beskriver de tester som körs med malltestverktyget för alla JSON-filer (JavaScript Object Notation). Exemplen innehåller testnamn och kodexempel som klarar eller misslyckas med testerna. Mer information om hur du kör tester eller hur du kör ett visst test finns i Testparametrar.

Använda giltig JSON-syntax

Testnamn: JSONFiles ska vara giltigt

Det här testet kontrollerar att alla JSON-filer innehåller giltig syntax. Till exempel azuredeploy.json, azuredeploy.parameters.json eller createUiDefinition.json-filer . Om testet misslyckas visas fel eller varningar för andra tester eller JSON-parsning.

Exempel på mallfil

Följande exempel misslyckas eftersom i azuredeploy.json saknas den inledande klammerparentesen ({) från parameters, comboBoxoch location.

{
  "$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')]"
    }
  }
}

Följande exempel godkänns.

{
  "$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')]"
    }
  }
}

Exempel på parameterfil

Följande exempel misslyckas eftersom azuredeploy.parameters.json använder en parameter utan .value

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value":
    }
  }
}

Följande exempel godkänns.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value": "westus"
    }
  }
}

CreateUiDefintion-exempel

Följande exempel misslyckas eftersom den inledande klammerparentesen ({) saknas outputs i avsnittet i createUiDefinition.json.

{
  "$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()]"
    }
  }
}

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()]"
    }
  }
}

Nästa steg