Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #3

Merged
merged 1 commit into from
Oct 20, 2021
Merged

Conversation

myc2h6o
Copy link

@myc2h6o myc2h6o commented Oct 20, 2021

  • Resource config definition update
    • Move resource "azurerm_key_vault_access_policy" "disk-encryption" { ... block to dependencies config, to avoid the duplicate definition of this resource. Earlier this resource is only needed for key rotate, but now the update of the new flag auto_key_rotation_enabled also requires this, and since in the document, it is already present, I'm moving it to the common resource dependencies, to make it simple to write the update and keyRotate test
    • Here is failed test output before this change
------ Stdout: -------
=== RUN   TestAccDiskEncryptionSet_update
=== PAUSE TestAccDiskEncryptionSet_update
=== CONT  TestAccDiskEncryptionSet_update
testcase.go:108: Step 3/6 error: Error running apply: exit status 1
Error: updating Disk Encryption Set "acctestDES-211019081335747893" (Resource Group "acctestRG-211019081335747893"): compute.DiskEncryptionSetsClient#Update: Failure sending request: StatusCode=400 -- Original Error: Code="KeyVaultAccessForbidden" Message="Unable to access key vault 'https://acctestkv-rzdvo.vault.azure.net/keys/examplekey'"
with azurerm_disk_encryption_set.test,
on terraform_plugin_test.tf line 69, in resource "azurerm_disk_encryption_set" "test":
69: resource "azurerm_disk_encryption_set" "test" {
--- FAIL: TestAccDiskEncryptionSet_update (385.25s)
FAIL
  • TestAccDataSourceDiskEncryptionSet_basic
    • Remove the duplicate basic config
    • Add check for default value of computed auto_key_rotation_enabled
  • TestAccDiskEncryptionSet_update
    • Remove duplicated complete config
  • TestAccDiskEncryptionSet_keyRotate
    • Remove grantAccessToKeyVault config after the move of azurerm_key_vault_access_policy resource, as it is now a common resource in dependencies, which will be present across all config.
  • Test results:
$ make acctests SERVICE='compute' TESTARGS='-run=DiskEncryptionSet_' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/compute -run=DiskEncryptionSet_ -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccDataSourceDiskEncryptionSet_basic
=== PAUSE TestAccDataSourceDiskEncryptionSet_basic
=== RUN   TestAccDataSourceDiskEncryptionSet_update
=== PAUSE TestAccDataSourceDiskEncryptionSet_update
=== RUN   TestAccDiskEncryptionSet_basic
=== PAUSE TestAccDiskEncryptionSet_basic
=== RUN   TestAccDiskEncryptionSet_requiresImport
=== PAUSE TestAccDiskEncryptionSet_requiresImport
=== RUN   TestAccDiskEncryptionSet_complete
=== PAUSE TestAccDiskEncryptionSet_complete
=== RUN   TestAccDiskEncryptionSet_update
=== PAUSE TestAccDiskEncryptionSet_update
=== RUN   TestAccDiskEncryptionSet_keyRotate
=== PAUSE TestAccDiskEncryptionSet_keyRotate
=== CONT  TestAccDataSourceDiskEncryptionSet_basic
=== CONT  TestAccDiskEncryptionSet_complete
=== CONT  TestAccDiskEncryptionSet_keyRotate
=== CONT  TestAccDataSourceDiskEncryptionSet_update
=== CONT  TestAccDiskEncryptionSet_update
=== CONT  TestAccDiskEncryptionSet_basic
=== CONT  TestAccDiskEncryptionSet_requiresImport
--- PASS: TestAccDiskEncryptionSet_complete (530.87s)
--- PASS: TestAccDiskEncryptionSet_basic (532.79s)
--- PASS: TestAccDataSourceDiskEncryptionSet_basic (545.35s)
--- PASS: TestAccDiskEncryptionSet_requiresImport (620.24s)
--- PASS: TestAccDataSourceDiskEncryptionSet_update (712.04s)
--- PASS: TestAccDiskEncryptionSet_update (726.25s)
--- PASS: TestAccDiskEncryptionSet_keyRotate (755.83s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/compute       756.524s

@Tbohunek
Copy link
Owner

I'm really sorry you have to keep working through my repo.

However, are you sure reducing those test cases preserves original functionality? I don't see those tests as duplicate, rather testing different scenarios.
Furthermore, you're even removing code/tests that were already there in Terraform before my PR and that exist also in other resources such as Key Vault.

@myc2h6o
Copy link
Author

myc2h6o commented Oct 20, 2021

No worries.
I'm not reducing the test cases, just moving the common key vault access policies assignment resource to the dependencies blocks.
You can see I removed func (r DiskEncryptionSetResource) grantAccessToKeyVault(data acceptance.TestData) string, which is originally meant to assign the access policies of the key vault to the disk encryption set. I moved it to func (DiskEncryptionSetResource) dependencies(data acceptance.TestData) string, which is the common part for all other config function.
The reason for this is that: updating the flag enable_auto_key_rotation requires a key vault access policy as well, so the update scenario will also need it. Instead of adding the duplicate assignment to the update test, I moved it to the common part.

@Tbohunek Tbohunek merged commit 40ba50c into Tbohunek:desautorotate Oct 20, 2021
@myc2h6o myc2h6o deleted the desautorotate_testfix branch October 20, 2021 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants