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