provider/github: Randomize issue label acc tests

This commit is contained in:
Radek Simko 2017-05-13 10:49:42 +02:00
parent b6edff80d8
commit af47810e30
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
1 changed files with 49 additions and 13 deletions

View File

@ -6,6 +6,7 @@ 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"
)
@ -13,27 +14,45 @@ import (
func TestAccGithubIssueLabel_basic(t *testing.T) {
var label github.Label
rString := acctest.RandString(5)
repoName := fmt.Sprintf("tf-acc-test-branch-issue-label-%s", rString)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGithubIssueLabelDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubIssueLabelConfig,
Config: testAccGithubIssueLabelConfig(repoName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists("github_issue_label.test", &label),
testAccCheckGithubIssueLabelAttributes(&label, "foo", "000000"),
),
},
{
Config: testAccGithubIssueLabelUpdateConfig,
Config: testAccGithubIssueLabelUpdateConfig(repoName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists("github_issue_label.test", &label),
testAccCheckGithubIssueLabelAttributes(&label, "bar", "FFFFFF"),
),
},
},
})
}
func TestAccGithubIssueLabel_existingLabel(t *testing.T) {
var label github.Label
rString := acctest.RandString(5)
repoName := fmt.Sprintf("tf-acc-test-branch-issue-label-%s", rString)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGithubIssueLabelDestroy,
Steps: []resource.TestStep{
{
Config: testAccGitHubIssueLabelExistsConfig,
Config: testAccGitHubIssueLabelExistsConfig(repoName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists("github_issue_label.test", &label),
testAccCheckGithubIssueLabelAttributes(&label, "enhancement", "FF00FF"),
@ -44,13 +63,16 @@ func TestAccGithubIssueLabel_basic(t *testing.T) {
}
func TestAccGithubIssueLabel_importBasic(t *testing.T) {
rString := acctest.RandString(5)
repoName := fmt.Sprintf("tf-acc-test-branch-issue-label-%s", rString)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGithubIssueLabelDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubIssueLabelConfig,
Config: testAccGithubIssueLabelConfig(repoName),
},
{
ResourceName: "github_issue_label.test",
@ -126,26 +148,39 @@ func testAccGithubIssueLabelDestroy(s *terraform.State) error {
return nil
}
var testAccGithubIssueLabelConfig string = fmt.Sprintf(`
func testAccGithubIssueLabelConfig(repoName string) string {
return fmt.Sprintf(`
resource "github_repository" "test" {
name = "%s"
}
resource "github_issue_label" "test" {
repository = "%s"
repository = "${github_repository.test.name}"
name = "foo"
color = "000000"
}
`, testRepo)
`, repoName)
}
func testAccGithubIssueLabelUpdateConfig(repoName string) string {
return fmt.Sprintf(`
resource "github_repository" "test" {
name = "%s"
}
var testAccGithubIssueLabelUpdateConfig string = fmt.Sprintf(`
resource "github_issue_label" "test" {
repository = "%s"
repository = "${github_repository.test.name}"
name = "bar"
color = "FFFFFF"
}
`, testRepo)
`, repoName)
}
var testAccGitHubIssueLabelExistsConfig string = fmt.Sprintf(`
func testAccGitHubIssueLabelExistsConfig(repoName string) string {
return fmt.Sprintf(`
// Create a repository which has the default labels
resource "github_repository" "test" {
name = "tf-acc-repo-label-abc1234"
name = "%s"
}
resource "github_issue_label" "test" {
@ -153,4 +188,5 @@ resource "github_issue_label" "test" {
name = "enhancement" // Important! This is a pre-created label
color = "FF00FF"
}
`)
`, repoName)
}