Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Test Suite For Team Data Source #600

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 80 additions & 24 deletions github/data_source_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

})
}