github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/bitbucket/resource_repository_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 TestAccBitbucketRepository_basic(t *testing.T) { 13 var repo Repository 14 15 testUser := os.Getenv("BITBUCKET_USERNAME") 16 testAccBitbucketRepositoryConfig := fmt.Sprintf(` 17 resource "bitbucket_repository" "test_repo" { 18 owner = "%s" 19 name = "%s" 20 } 21 `, testUser, testRepo) 22 23 resource.Test(t, resource.TestCase{ 24 PreCheck: func() { testAccPreCheck(t) }, 25 Providers: testAccProviders, 26 CheckDestroy: testAccCheckBitbucketRepositoryDestroy, 27 Steps: []resource.TestStep{ 28 resource.TestStep{ 29 Config: testAccBitbucketRepositoryConfig, 30 Check: resource.ComposeTestCheckFunc( 31 testAccCheckBitbucketRepositoryExists("bitbucket_repository.test_repo", &repo), 32 ), 33 }, 34 }, 35 }) 36 } 37 38 func testAccCheckBitbucketRepositoryDestroy(s *terraform.State) error { 39 client := testAccProvider.Meta().(*BitbucketClient) 40 rs, ok := s.RootModule().Resources["bitbucket_repository.test_repo"] 41 if !ok { 42 return fmt.Errorf("Not found %s", "bitbucket_repository.test_repo") 43 } 44 45 response, err := client.Get(fmt.Sprintf("2.0/repositories/%s/%s", rs.Primary.Attributes["owner"], rs.Primary.Attributes["name"])) 46 47 if err != nil { 48 return err 49 } 50 51 if response.StatusCode != 404 { 52 return fmt.Errorf("Repository still exists") 53 } 54 55 return nil 56 } 57 58 func testAccCheckBitbucketRepositoryExists(n string, repository *Repository) resource.TestCheckFunc { 59 return func(s *terraform.State) error { 60 rs, ok := s.RootModule().Resources[n] 61 if !ok { 62 return fmt.Errorf("Not found %s", n) 63 } 64 if rs.Primary.ID == "" { 65 return fmt.Errorf("No repository ID is set") 66 } 67 return nil 68 } 69 }