add retry for destroy on some acceptancy tests
parent
360f72775d
commit
d556ae2142
|
@ -2,6 +2,7 @@ package aws_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
|
@ -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{
|
||||
|
|
|
@ -2,6 +2,7 @@ package aws_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
|
@ -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{
|
||||
|
|
|
@ -2,6 +2,7 @@ package aws_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
|
@ -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{
|
||||
|
|
|
@ -2,6 +2,7 @@ package aws_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
|
@ -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{
|
||||
|
|
|
@ -2,6 +2,7 @@ package aws_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
|
@ -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{
|
||||
|
|
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -50,6 +56,7 @@ type AccTestCase struct {
|
|||
originalEnv []string
|
||||
tf map[string]*tfexec.Terraform
|
||||
ShouldRefreshBeforeDestroy bool
|
||||
RetryDestroy RetryConfig
|
||||
}
|
||||
|
||||
func (c *AccTestCase) initTerraformExecutor() error {
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue