Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Jan 21, 2020
1 parent 97b9f3f commit 26fe207
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions aws/resource_aws_cloudwatch_event_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -91,9 +90,10 @@ func testSweepCloudWatchEventTargets(region string) error {
func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) {
var target events.Target
resourceName := "aws_cloudwatch_event_target.test"
topicResourceName := "aws_sns_topic.test"
ruleName := acctest.RandomWithPrefix("tf-acc-cw-event-rule-basic")
snsTopicName1 := acctest.RandomWithPrefix("tf-acc")
snsTopicName2 := acctest.RandomWithPrefix("tf-acc")
snsTopicName1 := acctest.RandomWithPrefix("tf-acc-topic")
snsTopicName2 := acctest.RandomWithPrefix("tf-acc-topic-second")
targetID1 := acctest.RandomWithPrefix("tf-acc-cw-target")
targetID2 := acctest.RandomWithPrefix("tf-acc-cw-target")

Expand All @@ -108,8 +108,7 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) {
testAccCheckCloudWatchEventTargetExists(resourceName, &target),
resource.TestCheckResourceAttr(resourceName, "rule", ruleName),
resource.TestCheckResourceAttr(resourceName, "target_id", targetID1),
resource.TestMatchResourceAttr(resourceName, "arn",
regexp.MustCompile(fmt.Sprintf(":%s$", snsTopicName1))),
resource.TestCheckResourceAttrPair(resourceName, "arn", topicResourceName, "arn"),
),
},
{
Expand All @@ -118,8 +117,7 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) {
testAccCheckCloudWatchEventTargetExists(resourceName, &target),
resource.TestCheckResourceAttr(resourceName, "rule", ruleName),
resource.TestCheckResourceAttr(resourceName, "target_id", targetID2),
resource.TestMatchResourceAttr(resourceName, "arn",
regexp.MustCompile(fmt.Sprintf(":%s$", snsTopicName2))),
resource.TestCheckResourceAttrPair(resourceName, "arn", topicResourceName, "arn"),
),
},
{
Expand All @@ -135,6 +133,7 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) {
func TestAccAWSCloudWatchEventTarget_missingTargetId(t *testing.T) {
var target events.Target
resourceName := "aws_cloudwatch_event_target.test"
topicResourceName := "aws_sns_topic.test"
ruleName := acctest.RandomWithPrefix("tf-acc-cw-event-rule-missing-target-id")
snsTopicName := acctest.RandomWithPrefix("tf-acc")

Expand All @@ -148,8 +147,7 @@ func TestAccAWSCloudWatchEventTarget_missingTargetId(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchEventTargetExists(resourceName, &target),
resource.TestCheckResourceAttr(resourceName, "rule", ruleName),
resource.TestMatchResourceAttr(resourceName, "arn",
regexp.MustCompile(fmt.Sprintf(":%s$", snsTopicName))),
resource.TestCheckResourceAttrPair(resourceName, "arn", topicResourceName, "arn"),
),
},
{
Expand All @@ -165,6 +163,7 @@ func TestAccAWSCloudWatchEventTarget_missingTargetId(t *testing.T) {
func TestAccAWSCloudWatchEventTarget_full(t *testing.T) {
var target events.Target
resourceName := "aws_cloudwatch_event_target.test"
streamResourceName := "aws_kinesis_stream.test"
ruleName := acctest.RandomWithPrefix("tf-acc-cw-event-rule-full")
ssmDocumentName := acctest.RandomWithPrefix("tf_ssm_Document")
targetID := acctest.RandomWithPrefix("tf-acc-cw-target-full")
Expand All @@ -180,8 +179,7 @@ func TestAccAWSCloudWatchEventTarget_full(t *testing.T) {
testAccCheckCloudWatchEventTargetExists(resourceName, &target),
resource.TestCheckResourceAttr(resourceName, "rule", ruleName),
resource.TestCheckResourceAttr(resourceName, "target_id", targetID),
resource.TestMatchResourceAttr(resourceName, "arn",
regexp.MustCompile("^arn:aws:kinesis:.*:stream/tf_ssm_Document")),
resource.TestCheckResourceAttrPair(resourceName, "arn", streamResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "input", "{ \"source\": [\"aws.cloudtrail\"] }\n"),
resource.TestCheckResourceAttr(resourceName, "input_path", ""),
),
Expand Down

0 comments on commit 26fe207

Please sign in to comment.