你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

参数文件的测试用例

本文介绍了使用参数文件的模板测试工具包运行的测试。 例如,名为 azuredeploy.parameters.json的文件 . 这些示例包括测试名称以及通过或未通过测试的代码示例 。 有关如何运行测试或如何运行特定测试的详细信息,请参阅测试参数

该工具包包括适用于 Azure 资源管理器模板(ARM 模板)的测试用例,以及名为“azuredeploy.json”或“maintemplate.json”的主模板文件 。

使用有效的 contentVersion

测试名称:DeploymentParameters 应具有 ContentVersion

必须 contentVersion 包含格式 1.0.0.0 的字符串,并且仅使用数字。

以下示例失败,因为缺少 。contentVersion

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

以下示例 失败 ,因为 contentVersion is not a string。

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

以下示例通过了测试。

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

文件必须包含参数

测试名称:DeploymentParameters Should Have Parameters

参数文件必须包含该 parameters 部分。

下面的示例未通过。

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

以下示例通过了测试。

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

使用有效的 Schema 版本

测试名称:DeploymentParameters Should Have Schema

参数文件必须包含有效的架构版本。

参数文件有两个有效的 schema 版本:

  • https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#
  • https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#

下面的示例未通过。

{
  "$schema": "https://schema.management.azure.com/schemas/2021-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stgAcctName": {
      "value": "demostorage01"
    }
  }
}

以下示例通过了测试。

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

参数必须包含值

测试名称: DeploymentParameters Should Have Value

参数必须包含 a value 或 a reference。 对于密码等机密,密钥保管库在参数文件中使用 a reference 。 有关详细信息,请参阅 在部署期间使用 Azure Key Vault 传递安全参数值

以下示例 失败 ,因为 stgAcctName 没有 value.

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

以下示例通过了测试。

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

后续步骤