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