diff --git a/github/data_source_github_team_test.go b/github/data_source_github_team_test.go index edd75cb2ca..a3c6857bf6 100644 --- a/github/data_source_github_team_test.go +++ b/github/data_source_github_team_test.go @@ -6,32 +6,88 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform/helper/acctest" ) -func TestAccGithubTeamDataSource_noMatchReturnsError(t *testing.T) { - if err := testAccCheckOrganization(); err != nil { - t.Skipf("Skipping because %s.", err.Error()) - } - - slug := "non-existing" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckGithubTeamDataSourceConfig(slug), - ExpectError: regexp.MustCompile(`Could not find team`), - }, - }, +func TestAccGithubTeamDataSource(t *testing.T) { + + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + t.Run("queries an existing team without error", func(t *testing.T) { + + config := fmt.Sprintf(` + resource "github_team" "test" { + name = "tf-acc-test-%s" + } + + data "github_team" "test" { + slug = github_team.test.slug + } + `, randomID) + + check := resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrSet("data.github_team.test", "name"), + ) + + testCase := func(t *testing.T, mode string) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, mode) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: check, + }, + }, + }) + } + + t.Run("with an anonymous account", func(t *testing.T) { + t.Skip("anonymous account not supported for this operation") + }) + + t.Run("with an individual account", func(t *testing.T) { + t.Skip("individual account not supported for this operation") + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + }) -} -func testAccCheckGithubTeamDataSourceConfig(slug string) string { - return fmt.Sprintf(` -data "github_team" "test" { - slug = "%s" -} -`, slug) + t.Run("errors when querying a non-existing team", func(t *testing.T) { + + config := ` + data "github_team" "test" { + slug = "" + } + ` + + testCase := func(t *testing.T, mode string) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, mode) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: config, + ExpectError: regexp.MustCompile(`Not Found`), + }, + }, + }) + } + + t.Run("with an anonymous account", func(t *testing.T) { + t.Skip("anonymous account not supported for this operation") + }) + + t.Run("with an individual account", func(t *testing.T) { + testCase(t, individual) + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + + }) }