From 29c9b8497d5a204eda43d65a95921ca9ba16d344 Mon Sep 17 00:00:00 2001 From: Hector Rivas Gandara Date: Wed, 30 Mar 2016 16:03:37 +0100 Subject: [PATCH] provider/aws: Add tests for default_branch in new codecommit repos The provider should, when working on a new repository without branches: * Able to create a new repository even with default_branch defined. * Able to create a new repository without default_branch, and do not fail if default_branch is defined. --- ...resource_aws_codecommit_repository_test.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/builtin/providers/aws/resource_aws_codecommit_repository_test.go b/builtin/providers/aws/resource_aws_codecommit_repository_test.go index 0f7c8da53..e16bf2e29 100644 --- a/builtin/providers/aws/resource_aws_codecommit_repository_test.go +++ b/builtin/providers/aws/resource_aws_codecommit_repository_test.go @@ -53,6 +53,50 @@ func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) { }) } +func TestAccAWSCodeCommitRepository_create_default_branch(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCodeCommitRepositoryDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCodeCommitRepository_with_default_branch, + Check: resource.ComposeTestCheckFunc( + testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"), + resource.TestCheckResourceAttr( + "aws_codecommit_repository.test", "default_branch", "master"), + ), + }, + }, + }) +} + +func TestAccAWSCodeCommitRepository_create_and_update_default_branch(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", "default_branch", ""), + ), + }, + resource.TestStep{ + Config: testAccCodeCommitRepository_with_default_branch, + Check: resource.ComposeTestCheckFunc( + testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"), + resource.TestCheckResourceAttr( + "aws_codecommit_repository.test", "default_branch", "master"), + ), + }, + }, + }) +} + func testAccCheckCodeCommitRepositoryExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] @@ -129,3 +173,14 @@ resource "aws_codecommit_repository" "test" { description = "This is a test description - with changes" } ` + +const testAccCodeCommitRepository_with_default_branch = ` +provider "aws" { + region = "us-east-1" +} +resource "aws_codecommit_repository" "test" { + repository_name = "my_test_repository" + description = "This is a test description" + default_branch = "master" +} +`