Initial Acceptence test for repository

This commit is contained in:
Colin Wood 2016-09-08 12:27:29 -07:00
parent af24ac9f47
commit 32b5493e57
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,39 @@
package bitbucket
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"os"
"testing"
)
const testRepo string = "test-repo"
var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
func init() {
testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{
"bitbucket": testAccProvider,
}
}
func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("BITBUCKET_USERNAME"); v == "" {
t.Fatal("BITBUCKET_USERNAME must be set for acceptence tests")
}
if v := os.Getenv("BITBUCKET_PASSWORD"); v == "" {
t.Fatal("BITBUCKET_PASSWORD must be set for acceptence tests")
}
}

View File

@ -0,0 +1,53 @@
package bitbucket
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccBitbucketRepository_basic(t *testing.T) {
var repo Repository
testUser := os.Getenv("BITBUCKET_USERNAME")
testAccBitbucketRepositoryConfig := fmt.Sprintf(`
resource "bitbucket_repository" "test_repo" {
owner = "%s"
name = "%s"
}
`, testUser, testRepo)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBitbucketRepositoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBitbucketRepositoryConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketRepositoryExists("bitbucket_repository.test_repo", &repo),
),
},
},
})
}
func testAccCheckBitbucketRepositoryDestroy(s *terraform.State) error {
return nil
}
func testAccCheckBitbucketRepositoryExists(n string, repository *Repository) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No repository ID is set")
}
return nil
}
}