provider/github: Randomize repo and team names in acc tests (#12802)

This commit is contained in:
Radek Simko 2017-03-17 10:47:43 +00:00 committed by GitHub
parent 9e74548787
commit e6e2535d2e
5 changed files with 83 additions and 45 deletions

View File

@ -2,6 +2,7 @@ package github
import (
"context"
"log"
"github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/schema"
@ -44,11 +45,14 @@ func resourceGithubIssueLabelCreate(d *schema.ResourceData, meta interface{}) er
r := d.Get("repository").(string)
n := d.Get("name").(string)
c := d.Get("color").(string)
_, _, err := client.Issues.CreateLabel(context.TODO(), meta.(*Organization).name, r, &github.Label{
label := github.Label{
Name: &n,
Color: &c,
})
}
log.Printf("[DEBUG] Creating label: %#v", label)
_, resp, err := client.Issues.CreateLabel(context.TODO(), meta.(*Organization).name, r, &label)
log.Printf("[DEBUG] Response from creating label: %s", *resp)
if err != nil {
return err
}

View File

@ -7,12 +7,16 @@ import (
"testing"
"github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccGithubRepository_basic(t *testing.T) {
var repo github.Repository
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-%s", randString)
description := fmt.Sprintf("Terraform acceptance tests %s", randString)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -20,12 +24,12 @@ func TestAccGithubRepository_basic(t *testing.T) {
CheckDestroy: testAccCheckGithubRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubRepositoryConfig,
Config: testAccGithubRepositoryConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: "foo",
Description: "Terraform acceptance tests",
Name: name,
Description: description,
Homepage: "http://example.com/",
HasIssues: true,
HasWiki: true,
@ -35,12 +39,12 @@ func TestAccGithubRepository_basic(t *testing.T) {
),
},
{
Config: testAccGithubRepositoryUpdateConfig,
Config: testAccGithubRepositoryUpdateConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubRepositoryExists("github_repository.foo", &repo),
testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{
Name: "foo",
Description: "Terraform acceptance tests!",
Name: name,
Description: "Updated " + description,
Homepage: "http://example.com/",
DefaultBranch: "master",
}),
@ -51,13 +55,15 @@ func TestAccGithubRepository_basic(t *testing.T) {
}
func TestAccGithubRepository_importBasic(t *testing.T) {
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubRepositoryConfig,
Config: testAccGithubRepositoryConfig(randString),
},
{
ResourceName: "github_repository.foo",
@ -189,10 +195,11 @@ func testAccCheckGithubRepositoryDestroy(s *terraform.State) error {
return nil
}
const testAccGithubRepositoryConfig = `
func testAccGithubRepositoryConfig(randString string) string {
return fmt.Sprintf(`
resource "github_repository" "foo" {
name = "foo"
description = "Terraform acceptance tests"
name = "tf-acc-test-%s"
description = "Terraform acceptance tests %s"
homepage_url = "http://example.com/"
# So that acceptance tests can be run in a github organization
@ -203,12 +210,14 @@ resource "github_repository" "foo" {
has_wiki = true
has_downloads = true
}
`
`, randString, randString)
}
const testAccGithubRepositoryUpdateConfig = `
func testAccGithubRepositoryUpdateConfig(randString string) string {
return fmt.Sprintf(`
resource "github_repository" "foo" {
name = "foo"
description = "Terraform acceptance tests!"
name = "tf-acc-test-%s"
description = "Updated Terraform acceptance tests %s"
homepage_url = "http://example.com/"
# So that acceptance tests can be run in a github organization
@ -219,4 +228,5 @@ resource "github_repository" "foo" {
has_wiki = false
has_downloads = false
}
`
`, randString, randString)
}

View File

@ -6,12 +6,14 @@ import (
"testing"
"github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccGithubTeamMembership_basic(t *testing.T) {
var membership github.Membership
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
testAccGithubTeamMembershipUpdateConfig := fmt.Sprintf(`
resource "github_membership" "test_org_membership" {
@ -20,7 +22,7 @@ func TestAccGithubTeamMembership_basic(t *testing.T) {
}
resource "github_team" "test_team" {
name = "foo"
name = "tf-acc-test-team-membership-%s"
description = "Terraform acc test group"
}
@ -29,7 +31,7 @@ func TestAccGithubTeamMembership_basic(t *testing.T) {
username = "%s"
role = "maintainer"
}
`, testUser, testUser)
`, testUser, randString, testUser)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -37,7 +39,7 @@ func TestAccGithubTeamMembership_basic(t *testing.T) {
CheckDestroy: testAccCheckGithubTeamMembershipDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubTeamMembershipConfig,
Config: testAccGithubTeamMembershipConfig(randString, testUser),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubTeamMembershipExists("github_team_membership.test_team_membership", &membership),
testAccCheckGithubTeamMembershipRoleState("github_team_membership.test_team_membership", "member", &membership),
@ -55,13 +57,15 @@ func TestAccGithubTeamMembership_basic(t *testing.T) {
}
func TestAccGithubTeamMembership_importBasic(t *testing.T) {
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubTeamMembershipDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubTeamMembershipConfig,
Config: testAccGithubTeamMembershipConfig(randString, testUser),
},
{
ResourceName: "github_team_membership.test_team_membership",
@ -152,14 +156,15 @@ func testAccCheckGithubTeamMembershipRoleState(n, expected string, membership *g
}
}
var testAccGithubTeamMembershipConfig string = fmt.Sprintf(`
func testAccGithubTeamMembershipConfig(randString, username string) string {
return fmt.Sprintf(`
resource "github_membership" "test_org_membership" {
username = "%s"
role = "member"
}
resource "github_team" "test_team" {
name = "foo"
name = "tf-acc-test-team-membership-%s"
description = "Terraform acc test group"
}
@ -168,4 +173,5 @@ var testAccGithubTeamMembershipConfig string = fmt.Sprintf(`
username = "%s"
role = "member"
}
`, testUser, testUser)
`, username, randString, username)
}

View File

@ -6,12 +6,14 @@ import (
"testing"
"github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccGithubTeamRepository_basic(t *testing.T) {
var repository github.Repository
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -19,14 +21,14 @@ func TestAccGithubTeamRepository_basic(t *testing.T) {
CheckDestroy: testAccCheckGithubTeamRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubTeamRepositoryConfig,
Config: testAccGithubTeamRepositoryConfig(randString, testRepo),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubTeamRepositoryExists("github_team_repository.test_team_test_repo", &repository),
testAccCheckGithubTeamRepositoryRoleState("pull", &repository),
),
},
{
Config: testAccGithubTeamRepositoryUpdateConfig,
Config: testAccGithubTeamRepositoryUpdateConfig(randString, testRepo),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubTeamRepositoryExists("github_team_repository.test_team_test_repo", &repository),
testAccCheckGithubTeamRepositoryRoleState("push", &repository),
@ -37,13 +39,15 @@ func TestAccGithubTeamRepository_basic(t *testing.T) {
}
func TestAccGithubTeamRepository_importBasic(t *testing.T) {
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubTeamRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubTeamRepositoryConfig,
Config: testAccGithubTeamRepositoryConfig(randString, testRepo),
},
{
ResourceName: "github_team_repository.test_team_test_repo",
@ -148,9 +152,10 @@ func testAccCheckGithubTeamRepositoryDestroy(s *terraform.State) error {
return nil
}
var testAccGithubTeamRepositoryConfig string = fmt.Sprintf(`
func testAccGithubTeamRepositoryConfig(randString, repoName string) string {
return fmt.Sprintf(`
resource "github_team" "test_team" {
name = "foo"
name = "tf-acc-test-team-repo-%s"
description = "Terraform acc test group"
}
@ -159,11 +164,13 @@ resource "github_team_repository" "test_team_test_repo" {
repository = "%s"
permission = "pull"
}
`, testRepo)
`, randString, repoName)
}
var testAccGithubTeamRepositoryUpdateConfig string = fmt.Sprintf(`
func testAccGithubTeamRepositoryUpdateConfig(randString, repoName string) string {
return fmt.Sprintf(`
resource "github_team" "test_team" {
name = "foo"
name = "tf-acc-test-team-repo-%s"
description = "Terraform acc test group"
}
@ -172,4 +179,5 @@ resource "github_team_repository" "test_team_test_repo" {
repository = "%s"
permission = "push"
}
`, testRepo)
`, randString, repoName)
}

View File

@ -6,12 +6,16 @@ import (
"testing"
"github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccGithubTeam_basic(t *testing.T) {
var team github.Team
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-%s", randString)
updatedName := fmt.Sprintf("tf-acc-test-updated-%s", randString)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -19,17 +23,17 @@ func TestAccGithubTeam_basic(t *testing.T) {
CheckDestroy: testAccCheckGithubTeamDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubTeamConfig,
Config: testAccGithubTeamConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubTeamExists("github_team.foo", &team),
testAccCheckGithubTeamAttributes(&team, "foo", "Terraform acc test group"),
testAccCheckGithubTeamAttributes(&team, name, "Terraform acc test group"),
),
},
{
Config: testAccGithubTeamUpdateConfig,
Config: testAccGithubTeamUpdateConfig(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubTeamExists("github_team.foo", &team),
testAccCheckGithubTeamAttributes(&team, "foo2", "Terraform acc test group - updated"),
testAccCheckGithubTeamAttributes(&team, updatedName, "Terraform acc test group - updated"),
),
},
},
@ -37,13 +41,15 @@ func TestAccGithubTeam_basic(t *testing.T) {
}
func TestAccGithubTeam_importBasic(t *testing.T) {
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGithubTeamDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubTeamConfig,
Config: testAccGithubTeamConfig(randString),
},
{
ResourceName: "github_team.foo",
@ -112,18 +118,22 @@ func testAccCheckGithubTeamDestroy(s *terraform.State) error {
return nil
}
const testAccGithubTeamConfig = `
func testAccGithubTeamConfig(randString string) string {
return fmt.Sprintf(`
resource "github_team" "foo" {
name = "foo"
name = "tf-acc-test-%s"
description = "Terraform acc test group"
privacy = "secret"
}
`
`, randString)
}
const testAccGithubTeamUpdateConfig = `
func testAccGithubTeamUpdateConfig(randString string) string {
return fmt.Sprintf(`
resource "github_team" "foo" {
name = "foo2"
name = "tf-acc-test-updated-%s"
description = "Terraform acc test group - updated"
privacy = "closed"
}
`
`, randString)
}