2015-09-17 18:26:25 -05:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/codecommit"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSCodeCommitRepository_basic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccCodeCommitRepository_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-09-18 03:54:14 -05:00
|
|
|
func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckCodeCommitRepositoryDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccCodeCommitRepository_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_codecommit_repository.test", "description", "This is a test description"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccCodeCommitRepository_withChanges,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_codecommit_repository.test", "description", "This is a test description - with changes"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-09-17 18:26:25 -05:00
|
|
|
func testAccCheckCodeCommitRepositoryExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
codecommitconn := testAccProvider.Meta().(*AWSClient).codecommitconn
|
|
|
|
out, err := codecommitconn.GetRepository(&codecommit.GetRepositoryInput{
|
|
|
|
RepositoryName: aws.String(rs.Primary.ID),
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if out.RepositoryMetadata.Arn == nil {
|
|
|
|
return fmt.Errorf("No CodeCommit Repository Vault Found")
|
|
|
|
}
|
|
|
|
|
|
|
|
if *out.RepositoryMetadata.RepositoryName != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("CodeCommit Repository Mismatch - existing: %q, state: %q",
|
|
|
|
*out.RepositoryMetadata.RepositoryName, rs.Primary.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckCodeCommitRepositoryDestroy(s *terraform.State) error {
|
|
|
|
if len(s.RootModule().Resources) > 0 {
|
|
|
|
return fmt.Errorf("Expected all resources to be gone, but found: %#v",
|
|
|
|
s.RootModule().Resources)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccCodeCommitRepository_basic = `
|
2015-12-08 14:46:08 -06:00
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
2015-09-17 18:26:25 -05:00
|
|
|
resource "aws_codecommit_repository" "test" {
|
|
|
|
repository_name = "my_test_repository"
|
|
|
|
description = "This is a test description"
|
|
|
|
}
|
|
|
|
`
|
2015-09-18 03:54:14 -05:00
|
|
|
|
|
|
|
const testAccCodeCommitRepository_withChanges = `
|
2015-12-08 14:46:08 -06:00
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
2015-09-18 03:54:14 -05:00
|
|
|
resource "aws_codecommit_repository" "test" {
|
|
|
|
repository_name = "my_test_repository"
|
|
|
|
description = "This is a test description - with changes"
|
|
|
|
}
|
|
|
|
`
|