driftctl/pkg/resource/aws/aws_sqs_queue_test.go

76 lines
2.0 KiB
Go
Raw Permalink Normal View History

2021-01-27 10:49:25 +00:00
package aws_test
import (
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/r3labs/diff/v2"
awsresources "github.com/snyk/driftctl/enumeration/resource/aws"
2021-12-06 13:29:39 +00:00
"github.com/snyk/driftctl/pkg/analyser"
"github.com/snyk/driftctl/test"
"github.com/snyk/driftctl/test/acceptance"
"github.com/snyk/driftctl/test/acceptance/awsutils"
2021-01-27 10:49:25 +00:00
)
func TestAcc_Aws_SQSQueue(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-10-08 15:28:28 +00:00
Args: []string{"scan", "--deep"},
2021-01-27 10:49:25 +00:00
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
ShouldRetry: acceptance.LinearBackoff(10 * time.Minute),
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
},
},
},
})
}