driftctl/pkg/resource/aws/aws_sqs_queue_test.go

96 lines
2.5 KiB
Go
Raw Normal View History

2021-01-27 10:49:25 +00:00
package aws_test
import (
"testing"
"time"
"github.com/sirupsen/logrus"
2021-01-27 10:49:25 +00:00
2021-02-03 20:08:57 +00:00
"github.com/cloudskiff/driftctl/pkg/analyser"
awsresources "github.com/cloudskiff/driftctl/pkg/resource/aws"
2021-03-31 14:33:25 +00:00
"github.com/cloudskiff/driftctl/test"
2021-02-03 20:08:57 +00:00
"github.com/r3labs/diff/v2"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
2021-01-27 10:49:25 +00:00
"github.com/cloudskiff/driftctl/test/acceptance"
2021-02-03 20:08:57 +00:00
"github.com/cloudskiff/driftctl/test/acceptance/awsutils"
2021-01-27 10:49:25 +00:00
)
func TestAcc_AwsSQSQueue(t *testing.T) {
2021-02-03 20:08:57 +00:00
var mutatedQueue string
2021-01-27 10:49:25 +00:00
acceptance.Run(t, acceptance.AccTestCase{
2021-08-26 12:04:23 +00:00
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_sqs_queue"},
2021-07-20 12:42:52 +00:00
Args: []string{"scan", "--filter", "Type=='aws_sqs_queue'", "--deep"},
2021-01-27 10:49:25 +00:00
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
PreExec: func() {
err := acceptance.RetryFor(60*time.Second, func(doneCh chan struct{}) error {
return sqs.New(awsutils.Session()).ListQueuesPages(&sqs.ListQueuesInput{},
func(resp *sqs.ListQueuesOutput, lastPage bool) bool {
logrus.Debugf("Retrieved %d SQS queues", len(resp.QueueUrls))
if len(resp.QueueUrls) >= 2 {
doneCh <- struct{}{}
}
return !lastPage
},
)
})
if err != nil {
t.Fatal("Timeout while fetching SQS queues")
}
},
2021-03-31 14:33:25 +00:00
Check: func(result *test.ScanResult, stdout string, err error) {
2021-01-27 10:49:25 +00:00
if err != nil {
t.Fatal(err)
}
result.AssertInfrastructureIsInSync()
result.Equal(2, result.Summary().TotalManaged)
mutatedQueue = result.Managed()[0].ResourceId()
2021-02-03 20:08:57 +00:00
},
},
{
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
PreExec: func() {
client := sqs.New(awsutils.Session())
attributes := make(map[string]*string)
attributes["DelaySeconds"] = aws.String("200")
_, err := client.SetQueueAttributes(&sqs.SetQueueAttributesInput{
Attributes: attributes,
QueueUrl: aws.String(mutatedQueue),
})
if err != nil {
t.Fatal(err)
}
},
2021-03-31 14:33:25 +00:00
Check: func(result *test.ScanResult, stdout string, err error) {
2021-02-03 20:08:57 +00:00
if err != nil {
t.Fatal(err)
}
result.AssertDriftCountTotal(1)
result.AssertResourceHasDrift(
mutatedQueue,
awsresources.AwsSqsQueueResourceType,
analyser.Change{
Change: diff.Change{
Type: diff.UPDATE,
Path: []string{"delay_seconds"},
2021-02-03 20:08:57 +00:00
From: float64(0),
To: float64(200),
},
},
)
2021-01-27 10:49:25 +00:00
},
},
},
})
}