github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/bitbucket/resource_default_reviewers_test.go (about) 1 package bitbucket 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccBitbucketDefaultReviewers_basic(t *testing.T) { 13 14 testUser := os.Getenv("BITBUCKET_USERNAME") 15 testAccBitbucketDefaultReviewersConfig := fmt.Sprintf(` 16 resource "bitbucket_repository" "test_repo" { 17 owner = "%s" 18 name = "test-repo-default-reviewers" 19 } 20 21 resource "bitbucket_default_reviewers" "test_reviewers" { 22 owner = "%s" 23 repository = "${bitbucket_repository.test_repo.name}" 24 reviewers = [ 25 "%s", 26 ] 27 } 28 `, testUser, testUser, testUser) 29 30 resource.Test(t, resource.TestCase{ 31 PreCheck: func() { testAccPreCheck(t) }, 32 Providers: testAccProviders, 33 CheckDestroy: testAccCheckBitbucketDefaultReviewersDestroy, 34 Steps: []resource.TestStep{ 35 resource.TestStep{ 36 Config: testAccBitbucketDefaultReviewersConfig, 37 Check: resource.ComposeTestCheckFunc( 38 testAccCheckBitbucketDefaultReviewersExists("bitbucket_default_reviewers.test_reviewers"), 39 ), 40 }, 41 }, 42 }) 43 } 44 45 func testAccCheckBitbucketDefaultReviewersDestroy(s *terraform.State) error { 46 _, ok := s.RootModule().Resources["bitbucket_default_reviewers.test_reviewers"] 47 if !ok { 48 return fmt.Errorf("Not found %s", "bitbucket_default_reviewers.test_reviewers") 49 } 50 return nil 51 } 52 53 func testAccCheckBitbucketDefaultReviewersExists(n string) resource.TestCheckFunc { 54 return func(s *terraform.State) error { 55 rs, ok := s.RootModule().Resources[n] 56 57 if !ok { 58 return fmt.Errorf("Not found %s", n) 59 } 60 61 if rs.Primary.ID == "" { 62 return fmt.Errorf("No default reviewers ID is set") 63 } 64 65 return nil 66 } 67 }