0

I have an issue that I have now spent two hours on.

I have a Go test that deploys a Key Vault through the Azure SDK for Go.

note that I have this in my imports:

"github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault"

Here is the deployed 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"
}

}

As you can see keyVault.Properties.EnableSoftDelete is not there as it has never been set. That's fine.

The thing is I cant work out how to assert that this is expected:

assert.Nil(t, *keyVault.Properties.EnableSoftDelete, "Properties should be nil if soft delete not enabled")

The error I get is as follows:

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

And I can't work out how to make my test pass.

RuSs
  • 1,725
  • 1
  • 29
  • 47

1 Answers1

0

And the right answer is this:

assert.Nil(t, keyVault.Properties.EnableSoftDelete, "keyVault.Properties.EnableSoftDelete should be nil if soft delete not enabled")

Note the lack of a pointer (*) before "keyVault."

RuSs
  • 1,725
  • 1
  • 29
  • 47