github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/resource_aws_simpledb_domain_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/simpledb"
    10  	"github.com/hashicorp/terraform/helper/resource"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  func TestAccAWSSimpleDBDomain_basic(t *testing.T) {
    15  	resource.Test(t, resource.TestCase{
    16  		PreCheck:     func() { testAccPreCheck(t) },
    17  		Providers:    testAccProviders,
    18  		CheckDestroy: testAccCheckAWSSimpleDBDomainDestroy,
    19  		Steps: []resource.TestStep{
    20  			resource.TestStep{
    21  				Config: testAccAWSSimpleDBDomainConfig,
    22  				Check: resource.ComposeTestCheckFunc(
    23  					testAccCheckAWSSimpleDBDomainExists("aws_simpledb_domain.test_domain"),
    24  				),
    25  			},
    26  		},
    27  	})
    28  }
    29  
    30  func testAccCheckAWSSimpleDBDomainDestroy(s *terraform.State) error {
    31  	conn := testAccProvider.Meta().(*AWSClient).simpledbconn
    32  
    33  	for _, rs := range s.RootModule().Resources {
    34  		if rs.Type != "aws_simpledb_domain" {
    35  			continue
    36  		}
    37  
    38  		input := &simpledb.DomainMetadataInput{
    39  			DomainName: aws.String(rs.Primary.ID),
    40  		}
    41  		_, err := conn.DomainMetadata(input)
    42  		if err == nil {
    43  			return fmt.Errorf("Domain exists when it should be destroyed!")
    44  		}
    45  
    46  		// Verify the error is an API error, not something else
    47  		_, ok := err.(awserr.Error)
    48  		if !ok {
    49  			return err
    50  		}
    51  	}
    52  
    53  	return nil
    54  }
    55  
    56  func testAccCheckAWSSimpleDBDomainExists(n string) resource.TestCheckFunc {
    57  	return func(s *terraform.State) error {
    58  		rs, ok := s.RootModule().Resources[n]
    59  		if !ok {
    60  			return fmt.Errorf("Not found: %s", n)
    61  		}
    62  
    63  		if rs.Primary.ID == "" {
    64  			return fmt.Errorf("No SimpleDB domain with that name exists")
    65  		}
    66  
    67  		conn := testAccProvider.Meta().(*AWSClient).simpledbconn
    68  		input := &simpledb.DomainMetadataInput{
    69  			DomainName: aws.String(rs.Primary.ID),
    70  		}
    71  		_, err := conn.DomainMetadata(input)
    72  		return err
    73  	}
    74  }
    75  
    76  var testAccAWSSimpleDBDomainConfig = `
    77  resource "aws_simpledb_domain" "test_domain" {
    78    name = "terraform-test-domain"
    79  }
    80  `