terraform/builtin/providers/github/resource_github_issue_label...

157 lines
4.0 KiB
Go
Raw Normal View History

package github
import (
"context"
"fmt"
"testing"
"github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccGithubIssueLabel_basic(t *testing.T) {
var label github.Label
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGithubIssueLabelDestroy,
Steps: []resource.TestStep{
{
Config: testAccGithubIssueLabelConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists("github_issue_label.test", &label),
testAccCheckGithubIssueLabelAttributes(&label, "foo", "000000"),
),
},
{
Config: testAccGithubIssueLabelUpdateConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists("github_issue_label.test", &label),
testAccCheckGithubIssueLabelAttributes(&label, "bar", "FFFFFF"),
),
},
2017-03-31 17:44:00 +02:00
{
Config: testAccGitHubIssueLabelExistsConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists("github_issue_label.test", &label),
testAccCheckGithubIssueLabelAttributes(&label, "enhancement", "FF00FF"),
),
},
},
})
}
provider/github: supports importing resources (#10382) ``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccGithubIssueLabel_basic --- PASS: TestAccGithubIssueLabel_basic (0.91s) === RUN TestAccGithubIssueLabel_importBasic --- PASS: TestAccGithubIssueLabel_importBasic (0.41s) === RUN TestAccGithubMembership_basic --- PASS: TestAccGithubMembership_basic (0.84s) === RUN TestAccGithubMembership_importBasic --- PASS: TestAccGithubMembership_importBasic (0.53s) === RUN TestAccGithubRepositoryCollaborator_basic --- PASS: TestAccGithubRepositoryCollaborator_basic (0.64s) === RUN TestAccGithubRepositoryCollaborator_importBasic --- PASS: TestAccGithubRepositoryCollaborator_importBasic (0.74s) === RUN TestAccGithubRepository_basic --- PASS: TestAccGithubRepository_basic (1.54s) === RUN TestAccGithubRepository_importBasic --- PASS: TestAccGithubRepository_importBasic (0.77s) === RUN TestAccGithubTeamMembership_basic --- PASS: TestAccGithubTeamMembership_basic (1.59s) === RUN TestAccGithubTeamMembership_importBasic --- PASS: TestAccGithubTeamMembership_importBasic (0.95s) === RUN TestAccGithubTeamRepository_basic --- PASS: TestAccGithubTeamRepository_basic (1.45s) === RUN TestAccGithubTeamRepository_importBasic --- PASS: TestAccGithubTeamRepository_importBasic (0.75s) === RUN TestAccCheckGetPermissions --- PASS: TestAccCheckGetPermissions (0.00s) === RUN TestAccGithubTeam_basic --- PASS: TestAccGithubTeam_basic (0.79s) === RUN TestAccGithubTeam_importBasic --- PASS: TestAccGithubTeam_importBasic (0.54s) === RUN TestAccGithubUtilRole_validation --- PASS: TestAccGithubUtilRole_validation (0.00s) === RUN TestAccGithubUtilTwoPartID --- PASS: TestAccGithubUtilTwoPartID (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/github 12.455s ```
2016-11-28 18:30:24 +01:00
func TestAccGithubIssueLabel_importBasic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGithubIssueLabelDestroy,
Steps: []resource.TestStep{
{
provider/github: supports importing resources (#10382) ``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccGithubIssueLabel_basic --- PASS: TestAccGithubIssueLabel_basic (0.91s) === RUN TestAccGithubIssueLabel_importBasic --- PASS: TestAccGithubIssueLabel_importBasic (0.41s) === RUN TestAccGithubMembership_basic --- PASS: TestAccGithubMembership_basic (0.84s) === RUN TestAccGithubMembership_importBasic --- PASS: TestAccGithubMembership_importBasic (0.53s) === RUN TestAccGithubRepositoryCollaborator_basic --- PASS: TestAccGithubRepositoryCollaborator_basic (0.64s) === RUN TestAccGithubRepositoryCollaborator_importBasic --- PASS: TestAccGithubRepositoryCollaborator_importBasic (0.74s) === RUN TestAccGithubRepository_basic --- PASS: TestAccGithubRepository_basic (1.54s) === RUN TestAccGithubRepository_importBasic --- PASS: TestAccGithubRepository_importBasic (0.77s) === RUN TestAccGithubTeamMembership_basic --- PASS: TestAccGithubTeamMembership_basic (1.59s) === RUN TestAccGithubTeamMembership_importBasic --- PASS: TestAccGithubTeamMembership_importBasic (0.95s) === RUN TestAccGithubTeamRepository_basic --- PASS: TestAccGithubTeamRepository_basic (1.45s) === RUN TestAccGithubTeamRepository_importBasic --- PASS: TestAccGithubTeamRepository_importBasic (0.75s) === RUN TestAccCheckGetPermissions --- PASS: TestAccCheckGetPermissions (0.00s) === RUN TestAccGithubTeam_basic --- PASS: TestAccGithubTeam_basic (0.79s) === RUN TestAccGithubTeam_importBasic --- PASS: TestAccGithubTeam_importBasic (0.54s) === RUN TestAccGithubUtilRole_validation --- PASS: TestAccGithubUtilRole_validation (0.00s) === RUN TestAccGithubUtilTwoPartID --- PASS: TestAccGithubUtilTwoPartID (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/github 12.455s ```
2016-11-28 18:30:24 +01:00
Config: testAccGithubIssueLabelConfig,
},
{
provider/github: supports importing resources (#10382) ``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccGithubIssueLabel_basic --- PASS: TestAccGithubIssueLabel_basic (0.91s) === RUN TestAccGithubIssueLabel_importBasic --- PASS: TestAccGithubIssueLabel_importBasic (0.41s) === RUN TestAccGithubMembership_basic --- PASS: TestAccGithubMembership_basic (0.84s) === RUN TestAccGithubMembership_importBasic --- PASS: TestAccGithubMembership_importBasic (0.53s) === RUN TestAccGithubRepositoryCollaborator_basic --- PASS: TestAccGithubRepositoryCollaborator_basic (0.64s) === RUN TestAccGithubRepositoryCollaborator_importBasic --- PASS: TestAccGithubRepositoryCollaborator_importBasic (0.74s) === RUN TestAccGithubRepository_basic --- PASS: TestAccGithubRepository_basic (1.54s) === RUN TestAccGithubRepository_importBasic --- PASS: TestAccGithubRepository_importBasic (0.77s) === RUN TestAccGithubTeamMembership_basic --- PASS: TestAccGithubTeamMembership_basic (1.59s) === RUN TestAccGithubTeamMembership_importBasic --- PASS: TestAccGithubTeamMembership_importBasic (0.95s) === RUN TestAccGithubTeamRepository_basic --- PASS: TestAccGithubTeamRepository_basic (1.45s) === RUN TestAccGithubTeamRepository_importBasic --- PASS: TestAccGithubTeamRepository_importBasic (0.75s) === RUN TestAccCheckGetPermissions --- PASS: TestAccCheckGetPermissions (0.00s) === RUN TestAccGithubTeam_basic --- PASS: TestAccGithubTeam_basic (0.79s) === RUN TestAccGithubTeam_importBasic --- PASS: TestAccGithubTeam_importBasic (0.54s) === RUN TestAccGithubUtilRole_validation --- PASS: TestAccGithubUtilRole_validation (0.00s) === RUN TestAccGithubUtilTwoPartID --- PASS: TestAccGithubUtilTwoPartID (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/github 12.455s ```
2016-11-28 18:30:24 +01:00
ResourceName: "github_issue_label.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccCheckGithubIssueLabelExists(n string, label *github.Label) 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 issue label ID is set")
}
conn := testAccProvider.Meta().(*Organization).client
o := testAccProvider.Meta().(*Organization).name
r, n := parseTwoPartID(rs.Primary.ID)
githubLabel, _, err := conn.Issues.GetLabel(context.TODO(), o, r, n)
if err != nil {
return err
}
*label = *githubLabel
return nil
}
}
func testAccCheckGithubIssueLabelAttributes(label *github.Label, name, color string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *label.Name != name {
return fmt.Errorf("Issue label name does not match: %s, %s", *label.Name, name)
}
if *label.Color != color {
return fmt.Errorf("Issue label color does not match: %s, %s", *label.Color, color)
}
return nil
}
}
func testAccGithubIssueLabelDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*Organization).client
for _, rs := range s.RootModule().Resources {
if rs.Type != "github_issue_label" {
continue
}
o := testAccProvider.Meta().(*Organization).name
r, n := parseTwoPartID(rs.Primary.ID)
label, res, err := conn.Issues.GetLabel(context.TODO(), o, r, n)
if err == nil {
if label != nil &&
buildTwoPartID(label.Name, label.Color) == rs.Primary.ID {
return fmt.Errorf("Issue label still exists")
}
}
if res.StatusCode != 404 {
return err
}
return nil
}
return nil
}
var testAccGithubIssueLabelConfig string = fmt.Sprintf(`
resource "github_issue_label" "test" {
provider/github: supports importing resources (#10382) ``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccGithubIssueLabel_basic --- PASS: TestAccGithubIssueLabel_basic (0.91s) === RUN TestAccGithubIssueLabel_importBasic --- PASS: TestAccGithubIssueLabel_importBasic (0.41s) === RUN TestAccGithubMembership_basic --- PASS: TestAccGithubMembership_basic (0.84s) === RUN TestAccGithubMembership_importBasic --- PASS: TestAccGithubMembership_importBasic (0.53s) === RUN TestAccGithubRepositoryCollaborator_basic --- PASS: TestAccGithubRepositoryCollaborator_basic (0.64s) === RUN TestAccGithubRepositoryCollaborator_importBasic --- PASS: TestAccGithubRepositoryCollaborator_importBasic (0.74s) === RUN TestAccGithubRepository_basic --- PASS: TestAccGithubRepository_basic (1.54s) === RUN TestAccGithubRepository_importBasic --- PASS: TestAccGithubRepository_importBasic (0.77s) === RUN TestAccGithubTeamMembership_basic --- PASS: TestAccGithubTeamMembership_basic (1.59s) === RUN TestAccGithubTeamMembership_importBasic --- PASS: TestAccGithubTeamMembership_importBasic (0.95s) === RUN TestAccGithubTeamRepository_basic --- PASS: TestAccGithubTeamRepository_basic (1.45s) === RUN TestAccGithubTeamRepository_importBasic --- PASS: TestAccGithubTeamRepository_importBasic (0.75s) === RUN TestAccCheckGetPermissions --- PASS: TestAccCheckGetPermissions (0.00s) === RUN TestAccGithubTeam_basic --- PASS: TestAccGithubTeam_basic (0.79s) === RUN TestAccGithubTeam_importBasic --- PASS: TestAccGithubTeam_importBasic (0.54s) === RUN TestAccGithubUtilRole_validation --- PASS: TestAccGithubUtilRole_validation (0.00s) === RUN TestAccGithubUtilTwoPartID --- PASS: TestAccGithubUtilTwoPartID (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/github 12.455s ```
2016-11-28 18:30:24 +01:00
repository = "%s"
name = "foo"
color = "000000"
}
`, testRepo)
var testAccGithubIssueLabelUpdateConfig string = fmt.Sprintf(`
resource "github_issue_label" "test" {
provider/github: supports importing resources (#10382) ``` === RUN TestProvider --- PASS: TestProvider (0.00s) === RUN TestProvider_impl --- PASS: TestProvider_impl (0.00s) === RUN TestAccGithubIssueLabel_basic --- PASS: TestAccGithubIssueLabel_basic (0.91s) === RUN TestAccGithubIssueLabel_importBasic --- PASS: TestAccGithubIssueLabel_importBasic (0.41s) === RUN TestAccGithubMembership_basic --- PASS: TestAccGithubMembership_basic (0.84s) === RUN TestAccGithubMembership_importBasic --- PASS: TestAccGithubMembership_importBasic (0.53s) === RUN TestAccGithubRepositoryCollaborator_basic --- PASS: TestAccGithubRepositoryCollaborator_basic (0.64s) === RUN TestAccGithubRepositoryCollaborator_importBasic --- PASS: TestAccGithubRepositoryCollaborator_importBasic (0.74s) === RUN TestAccGithubRepository_basic --- PASS: TestAccGithubRepository_basic (1.54s) === RUN TestAccGithubRepository_importBasic --- PASS: TestAccGithubRepository_importBasic (0.77s) === RUN TestAccGithubTeamMembership_basic --- PASS: TestAccGithubTeamMembership_basic (1.59s) === RUN TestAccGithubTeamMembership_importBasic --- PASS: TestAccGithubTeamMembership_importBasic (0.95s) === RUN TestAccGithubTeamRepository_basic --- PASS: TestAccGithubTeamRepository_basic (1.45s) === RUN TestAccGithubTeamRepository_importBasic --- PASS: TestAccGithubTeamRepository_importBasic (0.75s) === RUN TestAccCheckGetPermissions --- PASS: TestAccCheckGetPermissions (0.00s) === RUN TestAccGithubTeam_basic --- PASS: TestAccGithubTeam_basic (0.79s) === RUN TestAccGithubTeam_importBasic --- PASS: TestAccGithubTeam_importBasic (0.54s) === RUN TestAccGithubUtilRole_validation --- PASS: TestAccGithubUtilRole_validation (0.00s) === RUN TestAccGithubUtilTwoPartID --- PASS: TestAccGithubUtilTwoPartID (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/github 12.455s ```
2016-11-28 18:30:24 +01:00
repository = "%s"
name = "bar"
color = "FFFFFF"
}
`, testRepo)
2017-03-31 17:44:00 +02:00
var testAccGitHubIssueLabelExistsConfig string = fmt.Sprintf(`
// Create a repository which has the default labels
resource "github_repository" "test" {
name = "tf-acc-repo-label-abc1234"
}
resource "github_issue_label" "test" {
repository = "${github_repository.test.name}"
name = "enhancement" // Important! This is a pre-created label
color = "FF00FF"
}
`)