Skip to content

Commit

Permalink
Review: Separate test configurations for SSE.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Aug 23, 2019
1 parent 25fb899 commit 7c14369
Showing 1 changed file with 93 additions and 74 deletions.
167 changes: 93 additions & 74 deletions aws/resource_aws_kinesis_firehose_delivery_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"regexp"
"strings"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/firehose"
Expand Down Expand Up @@ -66,7 +65,7 @@ func testSweepKinesisFirehoseDeliveryStreams(region string) error {
return fmt.Errorf("error deleting Kinesis Firehose Delivery Stream (%s): %s", name, err)
}

if err := waitForKinesisFirehoseDeliveryStreamDeletion(conn, name, 20*time.Minute); err != nil {
if err := waitForKinesisFirehoseDeliveryStreamDeletion(conn, name); err != nil {
return fmt.Errorf("error waiting for Kinesis Firehose Delivery Stream (%s) deletion: %s", name, err)
}
}
Expand Down Expand Up @@ -122,20 +121,68 @@ func TestAccAWSKinesisFirehoseDeliveryStream_importBasic(t *testing.T) {
}

func TestAccAWSKinesisFirehoseDeliveryStream_s3basic(t *testing.T) {
var stream firehose.DeliveryStreamDescription
ri := acctest.RandInt()
config := fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_s3basic,
ri, ri, ri, ri)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKinesisFirehoseDeliveryStreamDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
),
},
},
})
}

func TestAccAWSKinesisFirehoseDeliveryStream_s3basicWithSSE(t *testing.T) {
var stream firehose.DeliveryStreamDescription
rInt := acctest.RandInt()
rName := fmt.Sprintf("terraform-kinesis-firehose-basictest-%d", rInt)
config := fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_s3basic,
rInt, rInt, rInt, rInt)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKinesisFirehoseDeliveryStreamDestroy,
Steps: []resource.TestStep{
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName, rInt, false),
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basicWithSSE(rName, rInt, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.0.enabled", "true"),
),
},
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basicWithSSE(rName, rInt, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.0.enabled", "false"),
),
},
{
Config: config,
PlanOnly: true,
},
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basicWithSSE(rName, rInt, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.0.enabled", "true"),
),
},
},
Expand All @@ -146,6 +193,8 @@ func TestAccAWSKinesisFirehoseDeliveryStream_s3basicWithTags(t *testing.T) {
var stream firehose.DeliveryStreamDescription
rInt := acctest.RandInt()
rName := fmt.Sprintf("terraform-kinesis-firehose-basictest-%d", rInt)
config := fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_s3basic,
rInt, rInt, rInt, rInt)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -171,7 +220,7 @@ func TestAccAWSKinesisFirehoseDeliveryStream_s3basicWithTags(t *testing.T) {
),
},
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName, rInt, false),
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
Expand Down Expand Up @@ -226,8 +275,12 @@ func TestAccAWSKinesisFirehoseDeliveryStream_s3WithCloudwatchLogging(t *testing.

func TestAccAWSKinesisFirehoseDeliveryStream_s3ConfigUpdates(t *testing.T) {
var stream firehose.DeliveryStreamDescription
rInt := acctest.RandInt()
rName := fmt.Sprintf("terraform-kinesis-firehose-s3test-%d", rInt)

ri := acctest.RandInt()
preConfig := fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_s3basic,
ri, ri, ri, ri)
postConfig := fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamConfig_s3Updates,
ri, ri, ri, ri)

updatedS3DestinationConfig := &firehose.S3DestinationDescription{
BufferingHints: &firehose.BufferingHints{
Expand All @@ -242,15 +295,15 @@ func TestAccAWSKinesisFirehoseDeliveryStream_s3ConfigUpdates(t *testing.T) {
CheckDestroy: testAccCheckKinesisFirehoseDeliveryStreamDestroy,
Steps: []resource.TestStep{
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName, rInt, false),
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
),
},

{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3Updates(rName, rInt, false),
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, updatedS3DestinationConfig, nil, nil, nil, nil),
Expand All @@ -260,47 +313,6 @@ func TestAccAWSKinesisFirehoseDeliveryStream_s3ConfigUpdates(t *testing.T) {
})
}

func TestAccAWSKinesisFirehoseDeliveryStream_s3basicWithSSE(t *testing.T) {
var stream firehose.DeliveryStreamDescription
rInt := acctest.RandInt()
rName := fmt.Sprintf("terraform-kinesis-firehose-basictest-%d", rInt)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKinesisFirehoseDeliveryStreamDestroy,
Steps: []resource.TestStep{
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName, rInt, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.0.enabled", "true"),
),
},
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName, rInt, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.0.enabled", "false"),
),
},
{
Config: testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName, rInt, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisFirehoseDeliveryStreamExists("aws_kinesis_firehose_delivery_stream.test_stream", &stream),
testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(&stream, nil, nil, nil, nil, nil),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_kinesis_firehose_delivery_stream.test_stream", "server_side_encryption.0.enabled", "true"),
),
},
},
})
}

func TestAccAWSKinesisFirehoseDeliveryStream_ExtendedS3basic(t *testing.T) {
rString := acctest.RandString(8)
funcName := fmt.Sprintf("aws_kinesis_firehose_delivery_stream_test_%s", rString)
Expand Down Expand Up @@ -1528,24 +1540,18 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
`, rInt, rInt, rInt, rInt, rInt, rInt)
}

func testAccKinesisFirehoseDeliveryStreamConfig_s3basic(rName string, rInt int, sseEnabled bool) string {
return fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamBaseConfig, rInt, rInt, rInt) +
fmt.Sprintf(`
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
depends_on = ["aws_iam_role_policy.firehose"]
name = "%s"
destination = "s3"
s3_configuration {
role_arn = "${aws_iam_role.firehose.arn}"
bucket_arn = "${aws_s3_bucket.bucket.arn}"
}
server_side_encryption {
enabled = %t
}
}`, rName, sseEnabled)
}
var testAccKinesisFirehoseDeliveryStreamConfig_s3basic = testAccKinesisFirehoseDeliveryStreamBaseConfig + `
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
depends_on = ["aws_iam_role_policy.firehose"]
name = "terraform-kinesis-firehose-basictest-%d"
destination = "s3"
s3_configuration {
role_arn = "${aws_iam_role.firehose.arn}"
bucket_arn = "${aws_s3_bucket.bucket.arn}"
}
}`

func testAccKinesisFirehoseDeliveryStreamConfig_s3Updates(rName string, rInt int, sseEnabled bool) string {
func testAccKinesisFirehoseDeliveryStreamConfig_s3basicWithSSE(rName string, rInt int, sseEnabled bool) string {
return fmt.Sprintf(testAccKinesisFirehoseDeliveryStreamBaseConfig, rInt, rInt, rInt) +
fmt.Sprintf(`
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
Expand All @@ -1555,14 +1561,13 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
s3_configuration {
role_arn = "${aws_iam_role.firehose.arn}"
bucket_arn = "${aws_s3_bucket.bucket.arn}"
buffer_size = 10
buffer_interval = 400
compression_format = "GZIP"
}
server_side_encryption {
enabled = %t
}
}`, rName, sseEnabled)
}
server_side_encryption {
enabled = %t
}
}
`, rName, sseEnabled)
}

func testAccKinesisFirehoseDeliveryStreamConfig_s3basicWithTags(rName string, rInt int) string {
Expand Down Expand Up @@ -1617,6 +1622,20 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
}
}`

var testAccKinesisFirehoseDeliveryStreamConfig_s3Updates = testAccKinesisFirehoseDeliveryStreamBaseConfig + `
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
depends_on = ["aws_iam_role_policy.firehose"]
name = "terraform-kinesis-firehose-s3test-%d"
destination = "s3"
s3_configuration {
role_arn = "${aws_iam_role.firehose.arn}"
bucket_arn = "${aws_s3_bucket.bucket.arn}"
buffer_size = 10
buffer_interval = 400
compression_format = "GZIP"
}
}`

var testAccKinesisFirehoseDeliveryStreamConfig_extendedS3basic = testAccKinesisFirehoseDeliveryStreamBaseConfig + `
resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
depends_on = ["aws_iam_role_policy.firehose"]
Expand Down

0 comments on commit 7c14369

Please sign in to comment.