Skip to content

Conversation

@Didainius
Copy link
Contributor

@Didainius Didainius commented Mar 7, 2025

This PR attempts to trigger immediate cleanup after any failed test so that the next tests do not conflict for left behind duplicate entries.

Two things are done:

  • postTestChecks is deferred immediately after preTestChecks instead of keeping it at the end. This way it will be triggered even if the tests fail
  • postTestChecks will trigger leftover removal code in case the test is marked as failed and the leftover removal is not explicitly skippedt.Failed() && !skipLeftoversRemoval

Caveat - if the test panics - it won't help, but panic is a hard error anyway

Example recovery cleanup:

=== RUN   TestAccVcfaCertificateResource
    resource_vcfa_certificate_test.go:69: Step 1/4 error: Error running apply: exit status 1

        Error: [certificate library read] : error in HTTP GET request: RESOURCE_NOT_FOUND - Resource not found

          with vcfa_certificate.orgCertificate,
          on terraform_plugin_test.tf line 12, in resource "vcfa_certificate" "orgCertificate":
          12: resource "vcfa_certificate" "orgCertificate" {


        Error: [certificate library read] : error in HTTP GET request: RESOURCE_NOT_FOUND - Resource not found

          with vcfa_certificate.OrgWithPrivateCertificate,
          on terraform_plugin_test.tf line 19, in resource "vcfa_certificate" "OrgWithPrivateCertificate":
          19: resource "vcfa_certificate" "OrgWithPrivateCertificate" {


        Error: error adding certificate library item: error in HTTP POST request: BAD_REQUEST - [ 29-2025-03-07-13-24-31-417--28434f7b-eca2-4a24-aef7-cc455ab87a67 ] Cannot upload duplicate Certificate Libr
ary items.

          with vcfa_certificate.sysCertificate,
          on terraform_plugin_test.tf line 28, in resource "vcfa_certificate" "sysCertificate":
          28: resource "vcfa_certificate" "sysCertificate" {


        Error: error adding certificate library item: error in HTTP POST request: BAD_REQUEST - [ 30-2025-03-07-13-24-32-017--a727045d-36f8-412b-b373-4a5db116a646 ] Cannot upload duplicate Certificate Libr
ary items.

          with vcfa_certificate.sysCertificateWithPrivate,
          on terraform_plugin_test.tf line 35, in resource "vcfa_certificate" "sysCertificateWithPrivate":
          35: resource "vcfa_certificate" "sysCertificateWithPrivate" {

    testing_new.go:85: Error running post-test destroy, there may be dangling resources: exit status 1

        Error: [certificate library delete] error fetching certificate library: error in HTTP GET request: RESOURCE_NOT_FOUND - Resource not found


        Error: [certificate library delete] error fetching certificate library: error in HTTP GET request: RESOURCE_NOT_FOUND - Resource not found

Start leftovers removal    <------------- immediate cleanup
[vcfa_org] System (keep -)
[vcfa_org] test-org (DELETE)
         REMOVING Organization test-org
End leftovers removal
--- FAIL: TestAccVcfaCertificateResource (38.82s)
=== RUN   TestAccVcfaOrg
--- PASS: TestAccVcfaOrg (28.92s)
FAIL
Start leftovers removal. <------------- final cleanup that already exists
[vcfa_org] System (keep -)
End leftovers removal
FAIL    github.com/vmware/terraform-provider-vcfa/vcfa  83.386s
FAIL

@Didainius Didainius marked this pull request as ready for review March 7, 2025 11:32
@Didainius Didainius requested a review from adambarreiro as a code owner March 7, 2025 11:32
@Didainius Didainius merged commit 4b4897d into vmware:main Mar 7, 2025
2 checks passed
@Didainius Didainius deleted the cleanup-after-failed-test branch March 7, 2025 13:13
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.

3 participants