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

@@ -7,9 +7,14 @@ import (
)
func TestAccBitbucketBanner_basic(t *testing.T) {
testAccBitbucketBannerConfig := `
config := `
resource "bitbucketserver_banner" "test" {
message = "Test Banner\n*bold*"
}`
configModified := `
resource "bitbucketserver_banner" "test" {
message = "Test Banner changed"
}
`
@@ -18,19 +23,27 @@ func TestAccBitbucketBanner_basic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccBitbucketBannerConfig,
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "message", "Test Banner\n*bold*"),
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "enabled", "true"),
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "audience", "ALL"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "message", "Test Banner changed"),
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "enabled", "true"),
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "audience", "ALL"),
),
},
},
})
}
func TestAccBitbucketBanner_authenticated(t *testing.T) {
testAccBitbucketBannerConfig := `
config := `
resource "bitbucketserver_banner" "test" {
message = "Test Banner\n*bold*"
audience = "AUTHENTICATED"
@@ -42,7 +55,7 @@ func TestAccBitbucketBanner_authenticated(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccBitbucketBannerConfig,
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "message", "Test Banner\n*bold*"),
resource.TestCheckResourceAttr("bitbucketserver_banner.test", "audience", "AUTHENTICATED"),

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -22,6 +23,8 @@ func TestAccBitbucketResourceGlobalPermissionsGroup(t *testing.T) {
}
`, groupName)
configModified := strings.ReplaceAll(config, "ADMIN", "LICENSED_USER")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@@ -34,6 +37,14 @@ func TestAccBitbucketResourceGlobalPermissionsGroup(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_group.test", "permission", "ADMIN"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_group.test", "id", groupName),
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_group.test", "group", groupName),
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_group.test", "permission", "LICENSED_USER"),
),
},
},
})
}

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -24,6 +25,8 @@ func TestAccBitbucketResourceGlobalPermissionsUser(t *testing.T) {
}
`, user)
configModified := strings.ReplaceAll(config, "SYS_ADMIN", "LICENSED_USER")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@@ -36,6 +39,14 @@ func TestAccBitbucketResourceGlobalPermissionsUser(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_user.test", "permission", "SYS_ADMIN"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_user.test", "id", user),
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_user.test", "user", user),
resource.TestCheckResourceAttr("bitbucketserver_global_permissions_user.test", "permission", "LICENSED_USER"),
),
},
},
})
}

View File

@@ -2,6 +2,7 @@ package bitbucket
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform/helper/resource"
@@ -9,7 +10,7 @@ import (
)
func TestAccBitbucketMailServer(t *testing.T) {
testAccBitbucketMailServerConfig := `
config := `
resource "bitbucketserver_mail_server" "test" {
hostname = "mail.example.com"
port = 465
@@ -22,15 +23,25 @@ func TestAccBitbucketMailServer(t *testing.T) {
}
`
configModified := strings.ReplaceAll(config, "test@example.com", "test-updated@example.com")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBitbucketMailServerDestroy,
Steps: []resource.TestStep{
{
Config: testAccBitbucketMailServerConfig,
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketMailServerExists("bitbucketserver_mail_server.test"),
resource.TestCheckResourceAttr("bitbucketserver_mail_server.test", "sender_address", "test@example.com"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketMailServerExists("bitbucketserver_mail_server.test"),
resource.TestCheckResourceAttr("bitbucketserver_mail_server.test", "sender_address", "test-updated@example.com"),
),
},
},

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -24,6 +25,8 @@ func TestAccBitbucketResourceProjectPermissionsGroup(t *testing.T) {
}
`, projectKey)
configModified := strings.ReplaceAll(config, "PROJECT_WRITE", "PROJECT_READ")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@@ -37,6 +40,15 @@ func TestAccBitbucketResourceProjectPermissionsGroup(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_group.test", "permission", "PROJECT_WRITE"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_group.test", "id", projectKey+"/stash-users"),
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_group.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_group.test", "group", "stash-users"),
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_group.test", "permission", "PROJECT_READ"),
),
},
},
})
}

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -30,6 +31,8 @@ func TestAccBitbucketResourceProjectPermissionsUser(t *testing.T) {
}
`, projectKey)
configModified := strings.ReplaceAll(config, "PROJECT_READ", "PROJECT_WRITE")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@@ -43,6 +46,15 @@ func TestAccBitbucketResourceProjectPermissionsUser(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_user.test", "permission", "PROJECT_READ"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_user.test", "id", projectKey+"/mreynolds"),
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_user.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_user.test", "user", "mreynolds"),
resource.TestCheckResourceAttr("bitbucketserver_project_permissions_user.test", "permission", "PROJECT_WRITE"),
),
},
},
})
}

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -11,14 +12,17 @@ import (
)
func TestAccBitbucketProject(t *testing.T) {
testAccBitbucketProjectConfig := fmt.Sprintf(`
projectKey := fmt.Sprintf("TEST%v", rand.New(rand.NewSource(time.Now().UnixNano())).Int())
config := fmt.Sprintf(`
resource "bitbucketserver_project" "test" {
key = "TEST%v"
key = "%v"
name = "test-repo-for-repository-test"
description = "My description"
avatar = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg=="
}
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
`, projectKey)
configModified := strings.ReplaceAll(config, "My description", "My updated description")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@@ -26,9 +30,19 @@ func TestAccBitbucketProject(t *testing.T) {
CheckDestroy: testAccCheckBitbucketProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccBitbucketProjectConfig,
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketProjectExists("bitbucketserver_project.test"),
resource.TestCheckResourceAttr("bitbucketserver_project.test", "key", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_project.test", "description", "My description"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
testAccCheckBitbucketProjectExists("bitbucketserver_project.test"),
resource.TestCheckResourceAttr("bitbucketserver_project.test", "key", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_project.test", "description", "My updated description"),
),
},
},

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -30,6 +31,9 @@ func TestAccBitbucketResourceRepositoryPermissionsGroup(t *testing.T) {
}
`, projectKey, projectKey)
configModified := strings.ReplaceAll(config, "REPO_WRITE", "REPO_READ")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@@ -44,6 +48,16 @@ func TestAccBitbucketResourceRepositoryPermissionsGroup(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_group.test", "permission", "REPO_WRITE"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_group.test", "id", projectKey+"/test/stash-users"),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_group.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_group.test", "repository", "test"),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_group.test", "group", "stash-users"),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_group.test", "permission", "REPO_READ"),
),
},
},
})
}

View File

@@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
@@ -36,6 +37,8 @@ func TestAccBitbucketResourceRepositoryPermissionsUser(t *testing.T) {
}
`, projectKey, projectKey)
configModified := strings.ReplaceAll(config, "REPO_WRITE", "REPO_READ")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@@ -50,6 +53,16 @@ func TestAccBitbucketResourceRepositoryPermissionsUser(t *testing.T) {
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_user.test", "permission", "REPO_WRITE"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_user.test", "id", projectKey+"/test/mreynolds"),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_user.test", "project", projectKey),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_user.test", "repository", "test"),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_user.test", "user", "mreynolds"),
resource.TestCheckResourceAttr("bitbucketserver_repository_permissions_user.test", "permission", "REPO_READ"),
),
},
},
})
}

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"),
),
},
},

View File

@@ -4,11 +4,12 @@ import (
"fmt"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"strings"
"testing"
)
func TestAccBitbucketUserAccessToken(t *testing.T) {
testAccBitbucketUserConfig := `
config := `
resource "bitbucketserver_user_access_token" "test" {
user = "admin"
name = "my-token"
@@ -16,13 +17,15 @@ func TestAccBitbucketUserAccessToken(t *testing.T) {
}
`
configModified := strings.ReplaceAll(config, "my-token", "my-updated-token")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBitbucketUserAccessTokenDestroy,
Steps: []resource.TestStep{
{
Config: testAccBitbucketUserConfig,
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_user_access_token.test", "name", "my-token"),
resource.TestCheckResourceAttr("bitbucketserver_user_access_token.test", "permissions.#", "2"),
@@ -33,6 +36,18 @@ func TestAccBitbucketUserAccessToken(t *testing.T) {
resource.TestCheckResourceAttrSet("bitbucketserver_user_access_token.test", "access_token"),
),
},
{
Config: configModified,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("bitbucketserver_user_access_token.test", "name", "my-updated-token"),
resource.TestCheckResourceAttr("bitbucketserver_user_access_token.test", "permissions.#", "2"),
resource.TestCheckResourceAttr("bitbucketserver_user_access_token.test", "permissions.0", "REPO_READ"),
resource.TestCheckResourceAttr("bitbucketserver_user_access_token.test", "permissions.1", "PROJECT_WRITE"),
resource.TestCheckResourceAttrSet("bitbucketserver_user_access_token.test", "created_date"),
resource.TestCheckResourceAttrSet("bitbucketserver_user_access_token.test", "last_authenticated"),
resource.TestCheckResourceAttrSet("bitbucketserver_user_access_token.test", "access_token"),
),
},
},
})
}

View File

@@ -18,7 +18,6 @@ func TestAccBitbucketResourceUserGroup_basic(t *testing.T) {
group = "stash-users"
}
`
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,