github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/resource_aws_ses_configuration_set_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/service/ses"
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccAWSSESConfigurationSet_basic(t *testing.T) {
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck: func() {
    16  			testAccPreCheck(t)
    17  		},
    18  		Providers:    testAccProviders,
    19  		CheckDestroy: testAccCheckSESConfigurationSetDestroy,
    20  		Steps: []resource.TestStep{
    21  			resource.TestStep{
    22  				Config: testAccAWSSESConfigurationSetConfig,
    23  				Check: resource.ComposeTestCheckFunc(
    24  					testAccCheckAwsSESConfigurationSetExists("aws_ses_configuration_set.test"),
    25  				),
    26  			},
    27  		},
    28  	})
    29  }
    30  
    31  func testAccCheckSESConfigurationSetDestroy(s *terraform.State) error {
    32  	conn := testAccProvider.Meta().(*AWSClient).sesConn
    33  
    34  	for _, rs := range s.RootModule().Resources {
    35  		if rs.Type != "aws_ses_configuration_set" {
    36  			continue
    37  		}
    38  
    39  		response, err := conn.ListConfigurationSets(&ses.ListConfigurationSetsInput{})
    40  		if err != nil {
    41  			return err
    42  		}
    43  
    44  		found := false
    45  		for _, element := range response.ConfigurationSets {
    46  			if *element.Name == fmt.Sprintf("some-configuration-set-%d", escRandomInteger) {
    47  				found = true
    48  			}
    49  		}
    50  
    51  		if found {
    52  			return fmt.Errorf("The configuration set still exists")
    53  		}
    54  
    55  	}
    56  
    57  	return nil
    58  
    59  }
    60  
    61  func testAccCheckAwsSESConfigurationSetExists(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 configuration set not found: %s", n)
    66  		}
    67  
    68  		if rs.Primary.ID == "" {
    69  			return fmt.Errorf("SES configuration set ID not set")
    70  		}
    71  
    72  		conn := testAccProvider.Meta().(*AWSClient).sesConn
    73  
    74  		response, err := conn.ListConfigurationSets(&ses.ListConfigurationSetsInput{})
    75  		if err != nil {
    76  			return err
    77  		}
    78  
    79  		found := false
    80  		for _, element := range response.ConfigurationSets {
    81  			if *element.Name == fmt.Sprintf("some-configuration-set-%d", escRandomInteger) {
    82  				found = true
    83  			}
    84  		}
    85  
    86  		if !found {
    87  			return fmt.Errorf("The configuration set was not created")
    88  		}
    89  
    90  		return nil
    91  	}
    92  }
    93  
    94  var escRandomInteger = acctest.RandInt()
    95  var testAccAWSSESConfigurationSetConfig = fmt.Sprintf(`
    96  resource "aws_ses_configuration_set" "test" {
    97      name = "some-configuration-set-%d"
    98  }
    99  `, escRandomInteger)