github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/aws/resource_aws_codedeploy_app_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/codedeploy"
    10  	"github.com/hashicorp/terraform/helper/resource"
    11  	"github.com/hashicorp/terraform/terraform"
    12  )
    13  
    14  func TestAccAWSCodeDeployApp_basic(t *testing.T) {
    15  	resource.Test(t, resource.TestCase{
    16  		PreCheck:     func() { testAccPreCheck(t) },
    17  		Providers:    testAccProviders,
    18  		CheckDestroy: testAccCheckAWSCodeDeployAppDestroy,
    19  		Steps: []resource.TestStep{
    20  			resource.TestStep{
    21  				Config: testAccAWSCodeDeployApp,
    22  				Check: resource.ComposeTestCheckFunc(
    23  					testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
    24  				),
    25  			},
    26  			resource.TestStep{
    27  				Config: testAccAWSCodeDeployAppModified,
    28  				Check: resource.ComposeTestCheckFunc(
    29  					testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
    30  				),
    31  			},
    32  		},
    33  	})
    34  }
    35  
    36  func testAccCheckAWSCodeDeployAppDestroy(s *terraform.State) error {
    37  	conn := testAccProvider.Meta().(*AWSClient).codedeployconn
    38  
    39  	for _, rs := range s.RootModule().Resources {
    40  		if rs.Type != "aws_codedeploy_app" {
    41  			continue
    42  		}
    43  
    44  		_, err := conn.GetApplication(&codedeploy.GetApplicationInput{
    45  			ApplicationName: aws.String(rs.Primary.Attributes["name"]),
    46  		})
    47  
    48  		if err != nil {
    49  			// Verify the error is what we want
    50  			if ae, ok := err.(awserr.Error); ok && ae.Code() == "ApplicationDoesNotExistException" {
    51  				continue
    52  			}
    53  			return err
    54  		}
    55  
    56  		return fmt.Errorf("still exists")
    57  	}
    58  
    59  	return nil
    60  }
    61  
    62  func testAccCheckAWSCodeDeployAppExists(name string) resource.TestCheckFunc {
    63  	return func(s *terraform.State) error {
    64  		_, ok := s.RootModule().Resources[name]
    65  		if !ok {
    66  			return fmt.Errorf("Not found: %s", name)
    67  		}
    68  
    69  		return nil
    70  	}
    71  }
    72  
    73  var testAccAWSCodeDeployApp = `
    74  resource "aws_codedeploy_app" "foo" {
    75  	name = "foo"
    76  }`
    77  
    78  var testAccAWSCodeDeployAppModified = `
    79  resource "aws_codedeploy_app" "foo" {
    80  	name = "bar"
    81  }`