Skip to content

Commit

Permalink
add retry for destroy on some acceptancy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Guibert committed Jul 30, 2021
1 parent 360f727 commit d556ae2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_eip_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_Aws_EipAssociation(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_eip_association"},
Args: []string{"scan", "--filter", "Type=='aws_eip' || Type=='aws_eip_association'", "--tf-provider-version", "3.44.0", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_eip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_Aws_Eip(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_eip"},
Args: []string{"scan", "--filter", "Type=='aws_eip' || Type=='aws_eip_association'", "--tf-provider-version", "3.44.0", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_internet_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_AwsInternetGateway(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_internet_gateway"},
Args: []string{"scan", "--filter", "Type=='aws_internet_gateway'", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_route_table_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_AwsRouteTableAssociation(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_route_table_association"},
Args: []string{"scan", "--filter", "Type=='aws_route_table_association'", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
5 changes: 5 additions & 0 deletions pkg/resource/aws/aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws_test

import (
"testing"
"time"

"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
Expand All @@ -12,6 +13,10 @@ func TestAcc_AwsRoute(t *testing.T) {
TerraformVersion: "0.14.9",
Paths: []string{"./testdata/acc/aws_route"},
Args: []string{"scan", "--filter", "Type=='aws_route'", "--tf-provider-version", "3.44.0", "--deep"},
RetryDestroy: acceptance.RetryConfig{
Attempts: 3,
Delay: 5 * time.Second,
},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
Expand Down
17 changes: 17 additions & 0 deletions test/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cloudskiff/driftctl/pkg/analyser"
cmderrors "github.com/cloudskiff/driftctl/pkg/cmd/errors"
"github.com/eapache/go-resiliency/retrier"
"github.com/pkg/errors"

"github.com/sirupsen/logrus"
Expand All @@ -39,6 +40,11 @@ type AccCheck struct {
Check func(result *test.ScanResult, stdout string, err error)
}

type RetryConfig struct {
Attempts uint8
Delay time.Duration
}

type AccTestCase struct {
TerraformVersion string
Paths []string
Expand All @@ -50,6 +56,7 @@ type AccTestCase struct {
originalEnv []string
tf map[string]*tfexec.Terraform
ShouldRefreshBeforeDestroy bool
RetryDestroy RetryConfig
}

func (c *AccTestCase) initTerraformExecutor() error {
Expand Down Expand Up @@ -203,6 +210,16 @@ func (c *AccTestCase) terraformApply() error {
}

func (c *AccTestCase) terraformDestroy() error {
if c.RetryDestroy.Attempts == 0 {
return c.doDestroy()
}
r := retrier.New(retrier.ConstantBackoff(int(c.RetryDestroy.Attempts), c.RetryDestroy.Delay), nil)

return r.Run(c.doDestroy)

}

func (c *AccTestCase) doDestroy() error {
if c.ShouldRefreshBeforeDestroy {
if err := c.terraformRefresh(); err != nil {
return err
Expand Down

0 comments on commit d556ae2

Please sign in to comment.