Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure SDK for Go-在*keyVault.Properties.EnableSoftDelete上断言为零或为假_Azure_Go_Sdk_Testify - Fatal编程技术网

Azure SDK for Go-在*keyVault.Properties.EnableSoftDelete上断言为零或为假

Azure SDK for Go-在*keyVault.Properties.EnableSoftDelete上断言为零或为假,azure,go,sdk,testify,Azure,Go,Sdk,Testify,我有一个问题,我已经花了两个小时来解决 我有一个Go测试,它通过Azure SDK for Go部署了一个密钥库 请注意,我在导入的中有以下内容: "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault" 以下是已部署的密钥库: { "id": "/subscriptions/***/resourceGroups/rg-prd-aus-szg9v

我有一个问题,我已经花了两个小时来解决

我有一个Go测试,它通过Azure SDK for Go部署了一个密钥库

请注意,我在导入的
中有以下内容:

"github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault"
以下是已部署的密钥库:

{
"id": "/subscriptions/***/resourceGroups/rg-prd-aus-szg9vnoxmz/providers/Microsoft.KeyVault/vaults/kv-prd-aus-szg9vnoxmz",
"name": "kv-prd-aus-szg9vnoxmz",
"type": "Microsoft.KeyVault/vaults",
"location": "australiasoutheast",
"tags": {
    "example_key_vault_1": "example-kv"
},
"properties": {
    "sku": {
        "family": "A",
        "name": "premium"
    },
    "tenantId": "***",
    "networkAcls": {
        "bypass": "AzureServices",
        "defaultAction": "Deny",
        "ipRules": [
            {
                "value": "0.0.0.0/0"
            }
        ],
        "virtualNetworkRules": []
    },
    "accessPolicies": [],
    "enabledForDeployment": false,
    "enabledForDiskEncryption": false,
    "enabledForTemplateDeployment": false,
    "vaultUri": "https://***.vault.azure.net/",
    "provisioningState": "Succeeded"
}
}

如您所见,keyVault.Properties.EnableSoftDelete不存在,因为它从未设置过。 那很好

问题是我不知道如何断言这是意料之中的:

assert.Nil(t, *keyVault.Properties.EnableSoftDelete, "Properties should be nil if soft delete not enabled")
我得到的错误如下:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x73b86e]

goroutine 9 [running]:
testing.tRunner.func1(0xc000102200)
    /usr/lib/go-1.13/src/testing/testing.go:874 +0x3a3
panic(0x796100, 0xae18d0)
    /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
key_vault_test.assertTestCase1(0xc000102200, 0xc00015a0c0, 0x81be3e, 0x2f, 0x80f053, 0x13, 0x827ad8, 
0x827ad0, 0xc0000956e0)
    /home/russellmccloy/dev/terraform-azurerm-lab3-key-vault/test/key_vault_test.go:147 +0x5be
key_vault_test.TestKeyVaultCreation.func1(0xc000102200)
    /home/russellmccloy/dev/terraform-azurerm-lab3-key-vault/test/key_vault_test.go:78 +0x1ea
testing.tRunner(0xc000102200, 0xc00000f040)
    /usr/lib/go-1.13/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
    /usr/lib/go-1.13/src/testing/testing.go:960 +0x350
exit status 2
FAIL    key_vault_test  154.307s

我不知道如何通过考试。

正确的答案是:

assert.Nil(t, keyVault.Properties.EnableSoftDelete, "keyVault.Properties.EnableSoftDelete should be nil if soft delete not enabled")
请注意,“keyVault”之前缺少指针(*)