|
1 | 1 | package registry_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "fmt" |
5 | 6 | "testing" |
| 7 | + "time" |
6 | 8 |
|
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" |
7 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
8 | 11 | "github.com/hashicorp/terraform-plugin-testing/terraform" |
9 | 12 | registrySDK "github.com/scaleway/scaleway-sdk-go/api/registry/v1" |
@@ -80,30 +83,35 @@ func isNamespacePresent(tt *acctest.TestTools, n string) resource.TestCheckFunc |
80 | 83 |
|
81 | 84 | func isNamespaceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc { |
82 | 85 | 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() |
87 | 87 |
|
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 | + } |
92 | 93 |
|
93 | | - _, err = api.WaitForNamespace(®istrySDK.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 | + } |
97 | 98 |
|
98 | | - if err == nil { |
99 | | - return fmt.Errorf("namespace (%s) still exists", rs.Primary.ID) |
100 | | - } |
| 99 | + _, err = api.GetNamespace(®istrySDK.GetNamespaceRequest{ |
| 100 | + NamespaceID: id, |
| 101 | + Region: region, |
| 102 | + }) |
101 | 103 |
|
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 | + } |
104 | 112 | } |
105 | | - } |
106 | 113 |
|
107 | | - return nil |
| 114 | + return nil |
| 115 | + }) |
108 | 116 | } |
109 | 117 | } |
0 commit comments