Skip to content

Commit 569610a

Browse files
authored
[MAINT] Properly enable test sweeper (#3055)
* Align repo names in repo tests to enable sweeper Signed-off-by: Timo Sand <[email protected]> * Add `sweep` to `.PHONY` Signed-off-by: Timo Sand <[email protected]> * Fix `TestAccGithubActionsOrganizationSecretsDataSource` when Org already has secrets Signed-off-by: Timo Sand <[email protected]> * Standardize test team and repo names to use `testResourcePrefix` Signed-off-by: Timo Sand <[email protected]> * Refactor `GITHUB_IN_ORG_USER` tests to enable them Signed-off-by: Timo Sand <[email protected]> * Fix `TestAccGithubRepositoryCollaborators` to not use external user Signed-off-by: Timo Sand <[email protected]> * Add further comment to skipped test Signed-off-by: Timo Sand <[email protected]> * Re-add accidental deletion Signed-off-by: Timo Sand <[email protected]> --------- Signed-off-by: Timo Sand <[email protected]>
1 parent 3109c39 commit 569610a

102 files changed

Lines changed: 1230 additions & 1033 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GNUmakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TEST?=$$(go list ./... |grep -v 'vendor')
2+
SWEEP?=repositories,teams
23
WEBSITE_REPO=github.com/hashicorp/terraform-website
34
PKG_NAME=github
45

@@ -40,6 +41,10 @@ test-compile:
4041
fi
4142
CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS)
4243

44+
sweep:
45+
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
46+
go test $(TEST) -v -sweep=$(SWEEP) $(SWEEPARGS)
47+
4348
website:
4449
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
4550
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
@@ -58,4 +63,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
5863
endif
5964
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
6065

61-
.PHONY: build test testacc fmt lint lintcheck tools test-compile website website-lint website-test
66+
.PHONY: build test testacc fmt lint lintcheck tools test-compile website website-lint website-test sweep

github/acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
enterprise testMode = "enterprise"
2626
)
2727

28-
const testResourcePrefix = "test-acc-"
28+
const testResourcePrefix = "tf-acc-test-"
2929

3030
var (
3131
orgTestModes = []testMode{organization, team, enterprise}

github/data_source_github_actions_environment_public_key_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ import (
1111
func TestAccGithubActionsEnvironmentPublicKeyDataSource(t *testing.T) {
1212
t.Run("queries a repository environment public key without error", func(t *testing.T) {
1313
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
14+
repoName := fmt.Sprintf("%srepo-env-pubkey-%s", testResourcePrefix, randomID)
1415

1516
config := fmt.Sprintf(`
1617
resource "github_repository" "test" {
17-
name = "tf-acc-test-%[1]s"
18+
name = "%[1]s"
1819
auto_init = true
1920
}
2021
2122
resource "github_repository_environment" "test" {
2223
repository = github_repository.test.name
23-
environment = "tf-acc-test-%[1]s"
24+
environment = "tf-acc-test-%[2]s"
2425
}
2526
2627
data "github_actions_environment_public_key" "test" {
2728
repository = github_repository.test.name
2829
environment = github_repository_environment.test.environment
29-
}`, randomID)
30+
}`, repoName, randomID)
3031

3132
check := resource.ComposeTestCheckFunc(
3233
resource.TestCheckResourceAttrSet(

github/data_source_github_actions_environment_secrets_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import (
1111
func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) {
1212
t.Run("queries actions secrets from an environment", func(t *testing.T) {
1313
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
14+
repoName := fmt.Sprintf("%srepo-env-secrets-%s", testResourcePrefix, randomID)
1415

1516
config := fmt.Sprintf(`
1617
resource "github_repository" "test" {
17-
name = "tf-acc-test-%s"
18+
name = "%s"
1819
auto_init = true
1920
}
2021
@@ -29,7 +30,7 @@ func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) {
2930
repository = github_repository.test.name
3031
plaintext_value = "foo"
3132
}
32-
`, randomID)
33+
`, repoName)
3334

3435
config2 := config + `
3536
data "github_actions_environment_secrets" "test" {
@@ -39,7 +40,7 @@ func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) {
3940
`
4041

4142
check := resource.ComposeTestCheckFunc(
42-
resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)),
43+
resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "name", repoName),
4344
resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "secrets.#", "1"),
4445
resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "secrets.0.name", "SECRET_1"),
4546
resource.TestCheckResourceAttrSet("data.github_actions_environment_secrets.test", "secrets.0.created_at"),

github/data_source_github_actions_environment_variables_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212
func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) {
1313
t.Run("queries actions variables from an environment", func(t *testing.T) {
1414
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
15+
repoName := fmt.Sprintf("%srepo-env-vars-%s", testResourcePrefix, randomID)
1516

1617
config := fmt.Sprintf(`
1718
resource "github_repository" "test" {
18-
name = "tf-acc-test-%s"
19+
name = "%s"
1920
}
2021
2122
resource "github_repository_environment" "test" {
@@ -29,7 +30,7 @@ func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) {
2930
variable_name = "test_variable"
3031
value = "foo"
3132
}
32-
`, randomID)
33+
`, repoName)
3334

3435
config2 := config + `
3536
data "github_actions_environment_variables" "test" {

github/data_source_github_actions_organization_secrets_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func TestAccGithubActionsOrganizationSecretsDataSource(t *testing.T) {
2727
`
2828

2929
check := resource.ComposeTestCheckFunc(
30-
resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.#", "1"),
31-
resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.0.name", strings.ToUpper(fmt.Sprintf("ORG_SECRET_1_%s", randomID))),
32-
resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.0.visibility", "all"),
30+
// resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.#", "1"), // There is no feasible way to know how many secrets exist in the Org during test runs. And I couldn't find a "greater than" operator
31+
resource.TestCheckTypeSetElemAttr("data.github_actions_organization_secrets.test", "secrets.*.*", strings.ToUpper(fmt.Sprintf("ORG_SECRET_1_%s", randomID))),
32+
resource.TestCheckTypeSetElemAttr("data.github_actions_organization_secrets.test", "secrets.*.*", "all"),
3333
resource.TestCheckResourceAttrSet("data.github_actions_organization_secrets.test", "secrets.0.created_at"),
3434
resource.TestCheckResourceAttrSet("data.github_actions_organization_secrets.test", "secrets.0.updated_at"),
3535
)

github/data_source_github_actions_public_key_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ import (
1010

1111
func TestAccGithubActionsPublicKeyDataSource(t *testing.T) {
1212
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
13+
repoName := fmt.Sprintf("%srepo-actions-pubkey-%s", testResourcePrefix, randomID)
1314

1415
t.Run("queries a repository public key without error", func(t *testing.T) {
1516
config := fmt.Sprintf(`
1617
resource "github_repository" "test" {
17-
name = "tf-acc-test-%[1]s"
18+
name = "%[1]s"
1819
auto_init = true
1920
}
2021
2122
data "github_actions_public_key" "test" {
2223
repository = github_repository.test.name
2324
}
24-
`, randomID)
25+
`, repoName)
2526

2627
check := resource.ComposeTestCheckFunc(
2728
resource.TestCheckResourceAttrSet(

github/data_source_github_actions_registration_token_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ import (
1010

1111
func TestAccGithubActionsRegistrationTokenDataSource(t *testing.T) {
1212
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
13+
repoName := fmt.Sprintf("%srepo-actions-regtoken-%s", testResourcePrefix, randomID)
1314

1415
t.Run("get a repository registration token without error", func(t *testing.T) {
1516
config := fmt.Sprintf(`
1617
resource "github_repository" "test" {
17-
name = "tf-acc-test-%[1]s"
18+
name = "%[1]s"
1819
auto_init = true
1920
}
2021
2122
data "github_actions_registration_token" "test" {
2223
repository = github_repository.test.id
2324
}
24-
`, randomID)
25+
`, repoName)
2526

2627
check := resource.ComposeTestCheckFunc(
27-
resource.TestCheckResourceAttr("data.github_actions_registration_token.test", "repository", fmt.Sprintf("tf-acc-test-%s", randomID)),
28+
resource.TestCheckResourceAttr("data.github_actions_registration_token.test", "repository", repoName),
2829
resource.TestCheckResourceAttrSet("data.github_actions_registration_token.test", "token"),
2930
resource.TestCheckResourceAttrSet("data.github_actions_registration_token.test", "expires_at"),
3031
)

github/data_source_github_actions_repository_oidc_subject_claim_customization_template_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010

1111
func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSource(t *testing.T) {
1212
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
13+
repoName := fmt.Sprintf("%srepo-oidc-%s", testResourcePrefix, randomID)
1314

1415
t.Run("get an repository oidc subject claim customization template without error", func(t *testing.T) {
1516
config := fmt.Sprintf(`
1617
resource "github_repository" "test" {
17-
name = "tf-acc-test-%s"
18+
name = "%s"
1819
visibility = "private"
1920
}
2021
@@ -23,7 +24,7 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSour
2324
use_default = false
2425
include_claim_keys = ["repo", "context", "job_workflow_ref"]
2526
}
26-
`, randomID)
27+
`, repoName)
2728

2829
config2 := config + `
2930
data "github_actions_repository_oidc_subject_claim_customization_template" "test" {
@@ -33,15 +34,15 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSour
3334

3435
config3 := fmt.Sprintf(`
3536
resource "github_repository" "test" {
36-
name = "tf-acc-test-%s"
37+
name = "%s"
3738
visibility = "private"
3839
}
3940
4041
resource "github_actions_repository_oidc_subject_claim_customization_template" "test" {
4142
repository = github_repository.test.name
4243
use_default = true
4344
}
44-
`, randomID)
45+
`, repoName)
4546

4647
config4 := config3 + `
4748
data "github_actions_repository_oidc_subject_claim_customization_template" "test" {

github/data_source_github_actions_secrets_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import (
1111
func TestAccGithubActionsSecretsDataSource(t *testing.T) {
1212
t.Run("queries actions secrets from a repository", func(t *testing.T) {
1313
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
14+
repoName := fmt.Sprintf("%srepo-actions-secrets-%s", testResourcePrefix, randomID)
1415

1516
config := fmt.Sprintf(`
1617
resource "github_repository" "test" {
17-
name = "tf-acc-test-%s"
18+
name = "%s"
1819
auto_init = true
1920
}
2021
@@ -23,7 +24,7 @@ func TestAccGithubActionsSecretsDataSource(t *testing.T) {
2324
repository = github_repository.test.name
2425
plaintext_value = "foo"
2526
}
26-
`, randomID)
27+
`, repoName)
2728

2829
config2 := config + `
2930
data "github_actions_secrets" "test" {
@@ -32,7 +33,7 @@ func TestAccGithubActionsSecretsDataSource(t *testing.T) {
3233
`
3334

3435
check := resource.ComposeTestCheckFunc(
35-
resource.TestCheckResourceAttr("data.github_actions_secrets.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)),
36+
resource.TestCheckResourceAttr("data.github_actions_secrets.test", "name", repoName),
3637
resource.TestCheckResourceAttr("data.github_actions_secrets.test", "secrets.#", "1"),
3738
resource.TestCheckResourceAttr("data.github_actions_secrets.test", "secrets.0.name", "SECRET_1"),
3839
resource.TestCheckResourceAttrSet("data.github_actions_secrets.test", "secrets.0.created_at"),

0 commit comments

Comments
 (0)