2015-05-27 21:17:26 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/kinesis"
|
2015-05-27 21:17:26 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-07-21 16:42:02 +02:00
|
|
|
func TestAccAWSKinesisStream_basic(t *testing.T) {
|
2015-05-27 21:17:26 +02:00
|
|
|
var stream kinesis.StreamDescription
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckKinesisStreamDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccKinesisStreamConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream", &stream),
|
|
|
|
testAccCheckAWSKinesisStreamAttributes(&stream),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckKinesisStreamExists(n string, stream *kinesis.StreamDescription) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No Kinesis ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).kinesisconn
|
|
|
|
describeOpts := &kinesis.DescribeStreamInput{
|
2015-05-29 16:40:34 +02:00
|
|
|
StreamName: aws.String(rs.Primary.Attributes["name"]),
|
2015-07-28 22:29:46 +02:00
|
|
|
Limit: aws.Int64(1),
|
2015-05-27 21:17:26 +02:00
|
|
|
}
|
|
|
|
resp, err := conn.DescribeStream(describeOpts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*stream = *resp.StreamDescription
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSKinesisStreamAttributes(stream *kinesis.StreamDescription) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
if !strings.HasPrefix(*stream.StreamName, "terraform-kinesis-test") {
|
|
|
|
return fmt.Errorf("Bad Stream name: %s", *stream.StreamName)
|
|
|
|
}
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_kinesis_stream" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if *stream.StreamARN != rs.Primary.Attributes["arn"] {
|
|
|
|
return fmt.Errorf("Bad Stream ARN\n\t expected: %s\n\tgot: %s\n", rs.Primary.Attributes["arn"], *stream.StreamARN)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckKinesisStreamDestroy(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_kinesis_stream" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).kinesisconn
|
|
|
|
describeOpts := &kinesis.DescribeStreamInput{
|
2015-05-29 16:40:34 +02:00
|
|
|
StreamName: aws.String(rs.Primary.Attributes["name"]),
|
2015-07-28 22:29:46 +02:00
|
|
|
Limit: aws.Int64(1),
|
2015-05-27 21:17:26 +02:00
|
|
|
}
|
|
|
|
resp, err := conn.DescribeStream(describeOpts)
|
|
|
|
if err == nil {
|
|
|
|
if resp.StreamDescription != nil && *resp.StreamDescription.StreamStatus != "DELETING" {
|
|
|
|
return fmt.Errorf("Error: Stream still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccKinesisStreamConfig = fmt.Sprintf(`
|
|
|
|
resource "aws_kinesis_stream" "test_stream" {
|
|
|
|
name = "terraform-kinesis-test-%d"
|
|
|
|
shard_count = 1
|
|
|
|
}
|
|
|
|
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|