Added tests for updating resources

This commit is contained in:
Gavin Bunney
2019-10-18 11:17:08 -07:00
parent ec0c3ad91b
commit e9b753d854
12 changed files with 156 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -13,7 +14,7 @@ import (
func TestAccBitbucketRepository_basic(t *testing.T) {
var repo Repository
testAccBitbucketRepositoryConfig := fmt.Sprintf(`
config := fmt.Sprintf(`
resource "bitbucketserver_project" "test" {
key = "TEST%v"
name = "test-repo-for-repository-test"
@@ -22,18 +23,33 @@ func TestAccBitbucketRepository_basic(t *testing.T) {
resource "bitbucketserver_repository" "test_repo" {
project = bitbucketserver_project.test.key
name = "test-repo-for-repository-test"
description = "My Repo"
}
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
configModified := strings.ReplaceAll(config, "My Repo", "My Updated Repo")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBitbucketRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccBitbucketRepositoryConfig,
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketRepositoryExists("bitbucketserver_repository.test_repo", &repo),
resource.TestCheckResourceAttr("bitbucketserver_repository.test_repo", "slug", "test-repo-for-repository-test"),
resource.TestCheckResourceAttr("bitbucketserver_repository.test_repo", "name", "test-repo-for-repository-test"),
resource.TestCheckResourceAttr("bitbucketserver_repository.test_repo", "description", "My Repo"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketRepositoryExists("bitbucketserver_repository.test_repo", &repo),
resource.TestCheckResourceAttr("bitbucketserver_repository.test_repo", "slug", "test-repo-for-repository-test"),
resource.TestCheckResourceAttr("bitbucketserver_repository.test_repo", "name", "test-repo-for-repository-test"),
resource.TestCheckResourceAttr("bitbucketserver_repository.test_repo", "description", "My Updated Repo"),
),
},
},