Skip to content

Commit

Permalink
add retry
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Feb 19, 2024
1 parent 713ab45 commit a73a2b7
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions castai/resource_node_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/samber/lo"

"github.com/cenkalti/backoff/v4"
"github.com/golang/mock/gomock"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -581,19 +582,24 @@ func testAccCheckNodeTemplateDestroy(s *terraform.State) error {

id := rs.Primary.ID
clusterID := rs.Primary.Attributes["cluster_id"]
response, err := client.NodeTemplatesAPIListNodeTemplatesWithResponse(ctx, clusterID, &sdk.NodeTemplatesAPIListNodeTemplatesParams{IncludeDefault: lo.ToPtr(false)})
if err != nil {

if err := backoff.Retry(func() error {
response, err := client.NodeTemplatesAPIListNodeTemplatesWithResponse(ctx, clusterID, &sdk.NodeTemplatesAPIListNodeTemplatesParams{IncludeDefault: lo.ToPtr(false)})
if err != nil {
return err
}
if response.StatusCode() == http.StatusNotFound {
return nil
}
if len(*response.JSON200.Items) == 0 {
// Should be no templates
return nil
}

return fmt.Errorf("node template %q still exists; %v", id, string(response.GetBody()))
}, backoff.NewExponentialBackOff()); err != nil {
return err
}
if response.StatusCode() == http.StatusNotFound {
return nil
}
if len(*response.JSON200.Items) == 0 {
// Should be no templates
return nil
}

return fmt.Errorf("node template %q still exists; %v", id, string(response.GetBody()))
}

return nil
Expand Down

0 comments on commit a73a2b7

Please sign in to comment.