Skip to content

Commit 54a6f9b

Browse files
committed
test(registry): harden destroy checks with RetryContext
1 parent 7ee00a3 commit 54a6f9b

File tree

3 files changed

+704
-1529
lines changed

3 files changed

+704
-1529
lines changed

internal/services/registry/namespace_test.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package registry_test
22

33
import (
4+
"context"
45
"fmt"
56
"testing"
7+
"time"
68

9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
710
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
811
"github.com/hashicorp/terraform-plugin-testing/terraform"
912
registrySDK "github.com/scaleway/scaleway-sdk-go/api/registry/v1"
@@ -80,30 +83,35 @@ func isNamespacePresent(tt *acctest.TestTools, n string) resource.TestCheckFunc
8083

8184
func isNamespaceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
8285
return func(state *terraform.State) error {
83-
for _, rs := range state.RootModule().Resources {
84-
if rs.Type != "scaleway_registry_namespace" {
85-
continue
86-
}
86+
ctx := context.Background()
8787

88-
api, region, id, err := registry.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID)
89-
if err != nil {
90-
return err
91-
}
88+
return retry.RetryContext(ctx, 3*time.Minute, func() *retry.RetryError {
89+
for _, rs := range state.RootModule().Resources {
90+
if rs.Type != "scaleway_registry_namespace" {
91+
continue
92+
}
9293

93-
_, err = api.WaitForNamespace(&registrySDK.WaitForNamespaceRequest{
94-
NamespaceID: id,
95-
Region: region,
96-
})
94+
api, region, id, err := registry.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID)
95+
if err != nil {
96+
return retry.NonRetryableError(err)
97+
}
9798

98-
if err == nil {
99-
return fmt.Errorf("namespace (%s) still exists", rs.Primary.ID)
100-
}
99+
_, err = api.GetNamespace(&registrySDK.GetNamespaceRequest{
100+
NamespaceID: id,
101+
Region: region,
102+
})
101103

102-
if !httperrors.Is404(err) {
103-
return err
104+
switch {
105+
case err == nil:
106+
return retry.RetryableError(fmt.Errorf("namespace (%s) still exists", rs.Primary.ID))
107+
case httperrors.Is404(err):
108+
continue
109+
default:
110+
return retry.NonRetryableError(err)
111+
}
104112
}
105-
}
106113

107-
return nil
114+
return nil
115+
})
108116
}
109117
}

0 commit comments

Comments
 (0)