github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_ses_receipt_rule_set_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/aws/awserr"
     9  	"github.com/aws/aws-sdk-go/service/ses"
    10  	"github.com/hashicorp/terraform/helper/resource"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  func TestAccAWSSESReceiptRuleSet_basic(t *testing.T) {
    15  	resource.Test(t, resource.TestCase{
    16  		PreCheck: func() {
    17  			testAccPreCheck(t)
    18  		},
    19  		Providers:    testAccProviders,
    20  		CheckDestroy: testAccCheckSESReceiptRuleSetDestroy,
    21  		Steps: []resource.TestStep{
    22  			resource.TestStep{
    23  				Config: testAccAWSSESReceiptRuleSetConfig,
    24  				Check: resource.ComposeTestCheckFunc(
    25  					testAccCheckAwsSESReceiptRuleSetExists("aws_ses_receipt_rule_set.test"),
    26  				),
    27  			},
    28  		},
    29  	})
    30  }
    31  
    32  func testAccCheckSESReceiptRuleSetDestroy(s *terraform.State) error {
    33  	conn := testAccProvider.Meta().(*AWSClient).sesConn
    34  
    35  	for _, rs := range s.RootModule().Resources {
    36  		if rs.Type != "aws_ses_receipt_rule_set" {
    37  			continue
    38  		}
    39  
    40  		params := &ses.DescribeReceiptRuleSetInput{
    41  			RuleSetName: aws.String("just-a-test"),
    42  		}
    43  
    44  		_, err := conn.DescribeReceiptRuleSet(params)
    45  		if err == nil {
    46  			return fmt.Errorf("Receipt rule set %s still exists. Failing!", rs.Primary.ID)
    47  		}
    48  
    49  		// Verify the error is what we want
    50  		_, ok := err.(awserr.Error)
    51  		if !ok {
    52  			return err
    53  		}
    54  
    55  	}
    56  
    57  	return nil
    58  
    59  }
    60  
    61  func testAccCheckAwsSESReceiptRuleSetExists(n string) resource.TestCheckFunc {
    62  	return func(s *terraform.State) error {
    63  		rs, ok := s.RootModule().Resources[n]
    64  		if !ok {
    65  			return fmt.Errorf("SES Receipt Rule Set not found: %s", n)
    66  		}
    67  
    68  		if rs.Primary.ID == "" {
    69  			return fmt.Errorf("SES Receipt Rule Set name not set")
    70  		}
    71  
    72  		conn := testAccProvider.Meta().(*AWSClient).sesConn
    73  
    74  		params := &ses.DescribeReceiptRuleSetInput{
    75  			RuleSetName: aws.String("just-a-test"),
    76  		}
    77  
    78  		_, err := conn.DescribeReceiptRuleSet(params)
    79  		if err != nil {
    80  			return err
    81  		}
    82  
    83  		return nil
    84  	}
    85  }
    86  
    87  const testAccAWSSESReceiptRuleSetConfig = `
    88  resource "aws_ses_receipt_rule_set" "test" {
    89      rule_set_name = "just-a-test"
    90  }
    91  `