gpt4 book ai didi

Azure SDK for Go - 在 *keyVault.Properties.EnableSoftDelete 上断言 nil 或 false

转载 作者:行者123 更新时间:2023-12-01 22:20:48 25 4
gpt4 key购买 nike

我有一个问题,我现在已经花了两个小时。
我有一个通过 Azure SDK for Go 部署 Key Vault 的 Go 测试。
请注意,我的 imports 中有这个:

"github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault"
这是部署的 Key Vault:
{
"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”之前缺少指针 (*)。

关于Azure SDK for Go - 在 *keyVault.Properties.EnableSoftDelete 上断言 nil 或 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63625724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com