|
| 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 | + return nil |
| 40 | +} |
| 41 | + |
| 42 | +func testAccCheckBitbucketRepositoryExists(n string, repository *Repository) resource.TestCheckFunc { |
| 43 | + return func(s *terraform.State) error { |
| 44 | + rs, ok := s.RootModule().Resources[n] |
| 45 | + if !ok { |
| 46 | + return fmt.Errorf("Not found %s", n) |
| 47 | + } |
| 48 | + if rs.Primary.ID == "" { |
| 49 | + return fmt.Errorf("No repository ID is set") |
| 50 | + } |
| 51 | + return nil |
| 52 | + } |
| 53 | +} |
0 commit comments