diff --git a/GNUmakefile b/GNUmakefile index 876362fec7..b4e651ed50 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,5 @@ TEST?=$$(go list ./... |grep -v 'vendor') +SWEEP?=repositories,teams WEBSITE_REPO=github.com/hashicorp/terraform-website PKG_NAME=github @@ -40,6 +41,10 @@ test-compile: fi CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS) +sweep: + @echo "WARNING: This will destroy infrastructure. Use only in development accounts." + go test $(TEST) -v -sweep=$(SWEEP) $(SWEEPARGS) + website: ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) 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))) endif @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) -.PHONY: build test testacc fmt lint lintcheck tools test-compile website website-lint website-test +.PHONY: build test testacc fmt lint lintcheck tools test-compile website website-lint website-test sweep diff --git a/github/acc_test.go b/github/acc_test.go index 6bac9843ae..3bb6309244 100644 --- a/github/acc_test.go +++ b/github/acc_test.go @@ -25,7 +25,7 @@ const ( enterprise testMode = "enterprise" ) -const testResourcePrefix = "test-acc-" +const testResourcePrefix = "tf-acc-test-" var ( orgTestModes = []testMode{organization, team, enterprise} diff --git a/github/data_source_github_actions_environment_public_key_test.go b/github/data_source_github_actions_environment_public_key_test.go index 57b5acd68f..384cbbcbfb 100644 --- a/github/data_source_github_actions_environment_public_key_test.go +++ b/github/data_source_github_actions_environment_public_key_test.go @@ -11,22 +11,23 @@ import ( func TestAccGithubActionsEnvironmentPublicKeyDataSource(t *testing.T) { t.Run("queries a repository environment public key without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-pubkey-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } resource "github_repository_environment" "test" { repository = github_repository.test.name - environment = "tf-acc-test-%[1]s" + environment = "tf-acc-test-%[2]s" } data "github_actions_environment_public_key" "test" { repository = github_repository.test.name environment = github_repository_environment.test.environment - }`, randomID) + }`, repoName, randomID) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/data_source_github_actions_environment_secrets_test.go b/github/data_source_github_actions_environment_secrets_test.go index 10a6223bf5..0e960aa8f4 100644 --- a/github/data_source_github_actions_environment_secrets_test.go +++ b/github/data_source_github_actions_environment_secrets_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) { t.Run("queries actions secrets from an environment", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-secrets-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -29,7 +30,7 @@ func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) { repository = github_repository.test.name plaintext_value = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_actions_environment_secrets" "test" { @@ -39,7 +40,7 @@ func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "name", repoName), resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "secrets.#", "1"), resource.TestCheckResourceAttr("data.github_actions_environment_secrets.test", "secrets.0.name", "SECRET_1"), resource.TestCheckResourceAttrSet("data.github_actions_environment_secrets.test", "secrets.0.created_at"), diff --git a/github/data_source_github_actions_environment_variables_test.go b/github/data_source_github_actions_environment_variables_test.go index 999fe523ab..b41170bac9 100644 --- a/github/data_source_github_actions_environment_variables_test.go +++ b/github/data_source_github_actions_environment_variables_test.go @@ -12,10 +12,11 @@ import ( func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) { t.Run("queries actions variables from an environment", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-vars-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_environment" "test" { @@ -29,7 +30,7 @@ func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) { variable_name = "test_variable" value = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_actions_environment_variables" "test" { diff --git a/github/data_source_github_actions_organization_secrets_test.go b/github/data_source_github_actions_organization_secrets_test.go index 0324cb69cf..2217dbe539 100644 --- a/github/data_source_github_actions_organization_secrets_test.go +++ b/github/data_source_github_actions_organization_secrets_test.go @@ -27,9 +27,9 @@ func TestAccGithubActionsOrganizationSecretsDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.#", "1"), - resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.0.name", strings.ToUpper(fmt.Sprintf("ORG_SECRET_1_%s", randomID))), - resource.TestCheckResourceAttr("data.github_actions_organization_secrets.test", "secrets.0.visibility", "all"), + // 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 + resource.TestCheckTypeSetElemAttr("data.github_actions_organization_secrets.test", "secrets.*.*", strings.ToUpper(fmt.Sprintf("ORG_SECRET_1_%s", randomID))), + resource.TestCheckTypeSetElemAttr("data.github_actions_organization_secrets.test", "secrets.*.*", "all"), resource.TestCheckResourceAttrSet("data.github_actions_organization_secrets.test", "secrets.0.created_at"), resource.TestCheckResourceAttrSet("data.github_actions_organization_secrets.test", "secrets.0.updated_at"), ) diff --git a/github/data_source_github_actions_public_key_test.go b/github/data_source_github_actions_public_key_test.go index 1178529c38..cd05217215 100644 --- a/github/data_source_github_actions_public_key_test.go +++ b/github/data_source_github_actions_public_key_test.go @@ -10,18 +10,19 @@ import ( func TestAccGithubActionsPublicKeyDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-actions-pubkey-%s", testResourcePrefix, randomID) t.Run("queries a repository public key without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_actions_public_key" "test" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/data_source_github_actions_registration_token_test.go b/github/data_source_github_actions_registration_token_test.go index 46e4444d92..c4c53cb892 100644 --- a/github/data_source_github_actions_registration_token_test.go +++ b/github/data_source_github_actions_registration_token_test.go @@ -10,21 +10,22 @@ import ( func TestAccGithubActionsRegistrationTokenDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-actions-regtoken-%s", testResourcePrefix, randomID) t.Run("get a repository registration token without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_actions_registration_token" "test" { repository = github_repository.test.id } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_actions_registration_token.test", "repository", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_actions_registration_token.test", "repository", repoName), resource.TestCheckResourceAttrSet("data.github_actions_registration_token.test", "token"), resource.TestCheckResourceAttrSet("data.github_actions_registration_token.test", "expires_at"), ) diff --git a/github/data_source_github_actions_repository_oidc_subject_claim_customization_template_test.go b/github/data_source_github_actions_repository_oidc_subject_claim_customization_template_test.go index efdb1b77ff..6fec7776b4 100644 --- a/github/data_source_github_actions_repository_oidc_subject_claim_customization_template_test.go +++ b/github/data_source_github_actions_repository_oidc_subject_claim_customization_template_test.go @@ -10,11 +10,12 @@ import ( func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-oidc-%s", testResourcePrefix, randomID) t.Run("get an repository oidc subject claim customization template without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" } @@ -23,7 +24,7 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSour use_default = false include_claim_keys = ["repo", "context", "job_workflow_ref"] } - `, randomID) + `, repoName) config2 := config + ` data "github_actions_repository_oidc_subject_claim_customization_template" "test" { @@ -33,7 +34,7 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSour config3 := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" } @@ -41,7 +42,7 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSour repository = github_repository.test.name use_default = true } - `, randomID) + `, repoName) config4 := config3 + ` data "github_actions_repository_oidc_subject_claim_customization_template" "test" { diff --git a/github/data_source_github_actions_secrets_test.go b/github/data_source_github_actions_secrets_test.go index 3c788e44ba..c07a81be04 100644 --- a/github/data_source_github_actions_secrets_test.go +++ b/github/data_source_github_actions_secrets_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubActionsSecretsDataSource(t *testing.T) { t.Run("queries actions secrets from a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-actions-secrets-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -23,7 +24,7 @@ func TestAccGithubActionsSecretsDataSource(t *testing.T) { repository = github_repository.test.name plaintext_value = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_actions_secrets" "test" { @@ -32,7 +33,7 @@ func TestAccGithubActionsSecretsDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_actions_secrets.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_actions_secrets.test", "name", repoName), resource.TestCheckResourceAttr("data.github_actions_secrets.test", "secrets.#", "1"), resource.TestCheckResourceAttr("data.github_actions_secrets.test", "secrets.0.name", "SECRET_1"), resource.TestCheckResourceAttrSet("data.github_actions_secrets.test", "secrets.0.created_at"), diff --git a/github/data_source_github_actions_variables_test.go b/github/data_source_github_actions_variables_test.go index 5d53c924db..370fa38e52 100644 --- a/github/data_source_github_actions_variables_test.go +++ b/github/data_source_github_actions_variables_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubActionsVariablesDataSource(t *testing.T) { t.Run("queries actions variables from a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-actions-vars-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -23,7 +24,7 @@ func TestAccGithubActionsVariablesDataSource(t *testing.T) { repository = github_repository.test.name value = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_actions_variables" "test" { @@ -32,7 +33,7 @@ func TestAccGithubActionsVariablesDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_actions_variables.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_actions_variables.test", "name", repoName), resource.TestCheckResourceAttr("data.github_actions_variables.test", "variables.#", "1"), resource.TestCheckResourceAttr("data.github_actions_variables.test", "variables.0.name", "VARIABLE_1"), resource.TestCheckResourceAttr("data.github_actions_variables.test", "variables.0.value", "foo"), diff --git a/github/data_source_github_branch_protection_rules_test.go b/github/data_source_github_branch_protection_rules_test.go index 29a78787d3..df7138b636 100644 --- a/github/data_source_github_branch_protection_rules_test.go +++ b/github/data_source_github_branch_protection_rules_test.go @@ -11,17 +11,18 @@ import ( func TestAccGithubBranchProtectionRulesDataSource(t *testing.T) { t.Run("queries branch protection rules without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-bp-rules-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_branch_protection_rules" "all" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.github_branch_protection_rules.all", "rules.#", "0"), @@ -41,10 +42,11 @@ func TestAccGithubBranchProtectionRulesDataSource(t *testing.T) { t.Run("queries branch protection", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-bp-rules2-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -52,7 +54,7 @@ func TestAccGithubBranchProtectionRulesDataSource(t *testing.T) { repository_id = github_repository.test.name pattern = "main*" } - `, randomID) + `, repoName) config2 := config + ` data "github_branch_protection_rules" "all" { diff --git a/github/data_source_github_branch_test.go b/github/data_source_github_branch_test.go index ae2d4feaee..8be51e858e 100644 --- a/github/data_source_github_branch_test.go +++ b/github/data_source_github_branch_test.go @@ -12,10 +12,11 @@ import ( func TestAccGithubBranchDataSource(t *testing.T) { t.Run("queries an existing branch without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -23,7 +24,7 @@ func TestAccGithubBranchDataSource(t *testing.T) { repository = github_repository.test.name branch = "main" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr( @@ -46,10 +47,11 @@ func TestAccGithubBranchDataSource(t *testing.T) { // Can't test due to SDK and test framework limitations // t.Run("queries an invalid branch without error", func(t *testing.T) { // randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + // repoName := fmt.Sprintf("%sinvalid-branch-%s", testResourcePrefix, randomID) // config := fmt.Sprintf(` // resource "github_repository" "test" { - // name = "tf-acc-test-%[1]s" + // name = "%s" // auto_init = true // } @@ -57,7 +59,7 @@ func TestAccGithubBranchDataSource(t *testing.T) { // repository = github_repository.test.name // branch = "xxxxxx" // } - // `, randomID) + // `, repoName) // check := resource.ComposeTestCheckFunc( // resource.TestCheckResourceAttr( diff --git a/github/data_source_github_codespaces_public_key_test.go b/github/data_source_github_codespaces_public_key_test.go index 33d3617775..85dd76394d 100644 --- a/github/data_source_github_codespaces_public_key_test.go +++ b/github/data_source_github_codespaces_public_key_test.go @@ -10,18 +10,19 @@ import ( func TestAccGithubCodespacesPublicKeyDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-cs-pubkey-%s", testResourcePrefix, randomID) t.Run("queries a repository public key without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_codespaces_public_key" "test" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/data_source_github_codespaces_secrets_test.go b/github/data_source_github_codespaces_secrets_test.go index 27a3b053ae..c71a90270f 100644 --- a/github/data_source_github_codespaces_secrets_test.go +++ b/github/data_source_github_codespaces_secrets_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubCodespacesSecretsDataSource(t *testing.T) { t.Run("queries codespaces secrets from a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-cs-secrets-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -23,7 +24,7 @@ func TestAccGithubCodespacesSecretsDataSource(t *testing.T) { repository = github_repository.test.name plaintext_value = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_codespaces_secrets" "test" { @@ -32,7 +33,7 @@ func TestAccGithubCodespacesSecretsDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_codespaces_secrets.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_codespaces_secrets.test", "name", repoName), resource.TestCheckResourceAttr("data.github_codespaces_secrets.test", "secrets.#", "1"), resource.TestCheckResourceAttr("data.github_codespaces_secrets.test", "secrets.0.name", "CS_SECRET_1"), resource.TestCheckResourceAttrSet("data.github_codespaces_secrets.test", "secrets.0.created_at"), diff --git a/github/data_source_github_collaborators_test.go b/github/data_source_github_collaborators_test.go index 668c2d8da9..d7733331a1 100644 --- a/github/data_source_github_collaborators_test.go +++ b/github/data_source_github_collaborators_test.go @@ -10,7 +10,7 @@ import ( func TestAccGithubCollaboratorsDataSource(t *testing.T) { t.Run("gets all collaborators", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-collab-%s", acctest.RandString(5)) + repoName := fmt.Sprintf("%srepo-collab-%s", testResourcePrefix, acctest.RandString(5)) config := fmt.Sprintf(` resource "github_repository" "test" { name = "%s" @@ -40,7 +40,7 @@ data "github_collaborators" "test" { }) t.Run("gets admin collaborators", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-collab-%s", acctest.RandString(5)) + repoName := fmt.Sprintf("%srepo-collab-%s", testResourcePrefix, acctest.RandString(5)) config := fmt.Sprintf(` resource "github_repository" "test" { name = "%s" diff --git a/github/data_source_github_dependabot_public_key_test.go b/github/data_source_github_dependabot_public_key_test.go index 101e5d2034..6da9b92e5d 100644 --- a/github/data_source_github_dependabot_public_key_test.go +++ b/github/data_source_github_dependabot_public_key_test.go @@ -10,18 +10,19 @@ import ( func TestAccGithubDependabotPublicKeyDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-dep-pubkey-%s", testResourcePrefix, randomID) t.Run("queries a repository public key without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_actions_public_key" "test" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/data_source_github_dependabot_secrets_test.go b/github/data_source_github_dependabot_secrets_test.go index 88c699ce62..694d0c422b 100644 --- a/github/data_source_github_dependabot_secrets_test.go +++ b/github/data_source_github_dependabot_secrets_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubDependabotSecretsDataSource(t *testing.T) { t.Run("queries dependabot secrets from a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-dep-secrets-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -23,7 +24,7 @@ func TestAccGithubDependabotSecretsDataSource(t *testing.T) { repository = github_repository.test.name plaintext_value = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_dependabot_secrets" "test" { @@ -32,7 +33,7 @@ func TestAccGithubDependabotSecretsDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_dependabot_secrets.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_dependabot_secrets.test", "name", repoName), resource.TestCheckResourceAttr("data.github_dependabot_secrets.test", "secrets.#", "1"), resource.TestCheckResourceAttr("data.github_dependabot_secrets.test", "secrets.0.name", "DEP_SECRET_1"), resource.TestCheckResourceAttrSet("data.github_dependabot_secrets.test", "secrets.0.created_at"), diff --git a/github/data_source_github_issue_labels_test.go b/github/data_source_github_issue_labels_test.go index a5eae0b89c..c03b48493c 100644 --- a/github/data_source_github_issue_labels_test.go +++ b/github/data_source_github_issue_labels_test.go @@ -12,16 +12,17 @@ import ( func TestAccGithubIssueLabelsDataSource(t *testing.T) { t.Run("queries the labels for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-issue-labels-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_issue_labels" "test" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr( diff --git a/github/data_source_github_organization_custom_role_test.go b/github/data_source_github_organization_custom_role_test.go index e496057aa6..414f5e7dde 100644 --- a/github/data_source_github_organization_custom_role_test.go +++ b/github/data_source_github_organization_custom_role_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubOrganizationCustomRoleDataSource(t *testing.T) { t.Run("queries a custom repo role", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testResourceName := fmt.Sprintf("%sorg-custom-role-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_organization_custom_role" "test" { - name = "tf-acc-test-%s" + name = "%s" description = "Test role description" base_role = "read" permissions = [ @@ -22,7 +23,7 @@ func TestAccGithubOrganizationCustomRoleDataSource(t *testing.T) { "reopen_pull_request", ] } - `, randomID) + `, testResourceName) config2 := config + ` data "github_organization_custom_role" "test" { @@ -36,7 +37,7 @@ func TestAccGithubOrganizationCustomRoleDataSource(t *testing.T) { ), resource.TestCheckResourceAttr( "data.github_organization_custom_role.test", "name", - fmt.Sprintf(`tf-acc-test-%s`, randomID), + testResourceName, ), resource.TestCheckResourceAttr( "data.github_organization_custom_role.test", "description", diff --git a/github/data_source_github_organization_role_teams_test.go b/github/data_source_github_organization_role_teams_test.go index 9fa0370cf7..5ce65b1682 100644 --- a/github/data_source_github_organization_role_teams_test.go +++ b/github/data_source_github_organization_role_teams_test.go @@ -11,7 +11,7 @@ import ( func TestAccDataSourceGithubOrganizationRoleTeams(t *testing.T) { t.Run("get the organization role teams without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName := fmt.Sprintf("tf-acc-team-%s", randomID) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) roleId := 8134 config := fmt.Sprintf(` resource "github_team" "test" { @@ -52,8 +52,8 @@ func TestAccDataSourceGithubOrganizationRoleTeams(t *testing.T) { t.Run("get indirect organization role teams without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName1 := fmt.Sprintf("tf-acc-team-1-%s", randomID) - teamName2 := fmt.Sprintf("tf-acc-team-2-%s", randomID) + teamName1 := fmt.Sprintf("%steam-1-%s", testResourcePrefix, randomID) + teamName2 := fmt.Sprintf("%steam-2-%s", testResourcePrefix, randomID) roleId := 8134 config := fmt.Sprintf(` resource "github_team" "test_1" { diff --git a/github/data_source_github_organization_role_users_test.go b/github/data_source_github_organization_role_users_test.go index 3814b1fe94..895d2380d7 100644 --- a/github/data_source_github_organization_role_users_test.go +++ b/github/data_source_github_organization_role_users_test.go @@ -2,7 +2,6 @@ package github import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -10,11 +9,6 @@ import ( ) func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) { - login := os.Getenv("GITHUB_IN_ORG_USER") - if len(login) == 0 { - t.Skip("set inOrgUser to unskip this test run") - } - t.Run("get the organization role users without error", func(t *testing.T) { roleId := 8134 config := fmt.Sprintf(` @@ -30,7 +24,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) { github_organization_role_user.test ] } - `, roleId, login) + `, roleId, testAccConf.testOrgUser) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -42,7 +36,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) { resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.#"), resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.#", "1"), resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.0.user_id"), - resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", login), + resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", testAccConf.testOrgUser), ), }, }, @@ -51,7 +45,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) { t.Run("get indirect organization role users without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName := fmt.Sprintf("tf-acc-team-%s", randomID) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) roleId := 8134 config := fmt.Sprintf(` resource "github_team" "test" { @@ -76,7 +70,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) { github_organization_role_team.test ] } - `, teamName, login, roleId) + `, teamName, testAccConf.testOrgUser, roleId) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -88,7 +82,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) { resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.#"), resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.#", "1"), resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.0.user_id"), - resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", login), + resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", testAccConf.testOrgUser), ), }, }, diff --git a/github/data_source_github_organization_security_managers_test.go b/github/data_source_github_organization_security_managers_test.go index 3997c7ca58..0fa0a60500 100644 --- a/github/data_source_github_organization_security_managers_test.go +++ b/github/data_source_github_organization_security_managers_test.go @@ -11,7 +11,7 @@ import ( func TestAccDataSourceGithubOrganizationSecurityManagers(t *testing.T) { t.Run("get the organization security managers without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName := fmt.Sprintf("tf-acc-%s", randomID) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { diff --git a/github/data_source_github_organization_teams_test.go b/github/data_source_github_organization_teams_test.go index c6b297102e..31d082283c 100644 --- a/github/data_source_github_organization_teams_test.go +++ b/github/data_source_github_organization_teams_test.go @@ -11,7 +11,7 @@ import ( func TestAccGithubOrganizationTeamsDataSource(t *testing.T) { t.Run("queries", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName := fmt.Sprintf("tf-acc-test-0-%s", randomID) + teamName := fmt.Sprintf("%steam-0-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { diff --git a/github/data_source_github_organization_test.go b/github/data_source_github_organization_test.go index 8016804ec6..f9d4f0a5c1 100644 --- a/github/data_source_github_organization_test.go +++ b/github/data_source_github_organization_test.go @@ -57,10 +57,11 @@ func TestAccGithubOrganizationDataSource(t *testing.T) { t.Run("queries for an organization with archived repos", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-archived-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "archived" { - name = "tf-acc-archived-%s" + name = "%s" archived = true } @@ -85,7 +86,7 @@ func TestAccGithubOrganizationDataSource(t *testing.T) { output "should_be_true" { value = contains(data.github_organization.all_repos.repositories, github_repository.archived.full_name) } - `, randomID, testAccConf.owner, testAccConf.owner) + `, repoName, testAccConf.owner, testAccConf.owner) check := resource.ComposeTestCheckFunc( resource.TestCheckOutput("should_be_false", "false"), diff --git a/github/data_source_github_ref_test.go b/github/data_source_github_ref_test.go index 30e1a7ca29..9af723c874 100644 --- a/github/data_source_github_ref_test.go +++ b/github/data_source_github_ref_test.go @@ -11,9 +11,10 @@ import ( func TestAccGithubRefDataSource(t *testing.T) { t.Run("queries an existing branch ref without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ref-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -22,7 +23,7 @@ func TestAccGithubRefDataSource(t *testing.T) { repository = github_repository.test.name ref = "heads/main" } - `, randomID, testAccConf.owner) + `, repoName, testAccConf.owner) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -42,9 +43,10 @@ func TestAccGithubRefDataSource(t *testing.T) { // Can't test due to SDK and test framework limitations // t.Run("queries an invalid ref without error", func(t *testing.T) { // randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + // repoName := fmt.Sprintf("%srepo-invalid-ref-%s", testResourcePrefix, randomID) // config := fmt.Sprintf(` // resource "github_repository" "test" { - // name = "tf-acc-test-%[1]s" + // name = "%s" // auto_init = true // } @@ -52,7 +54,7 @@ func TestAccGithubRefDataSource(t *testing.T) { // repository = github_repository.test.id // ref = "heads/xxxxxx" // } - // `, randomID) + // `, repoName) // check := resource.ComposeTestCheckFunc( // resource.TestCheckNoResourceAttr( diff --git a/github/data_source_github_repository_autolink_references_test.go b/github/data_source_github_repository_autolink_references_test.go index f3ecf95b1f..54261ec959 100644 --- a/github/data_source_github_repository_autolink_references_test.go +++ b/github/data_source_github_repository_autolink_references_test.go @@ -10,11 +10,12 @@ import ( func TestAccGithubRepositoryAutolinkReferencesDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-autolink-refs-%s", testResourcePrefix, randomID) t.Run("queries autolink references", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -24,7 +25,7 @@ func TestAccGithubRepositoryAutolinkReferencesDataSource(t *testing.T) { key_prefix = "TEST1-" target_url_template = "https://example.com/TEST-" } - `, randomID) + `, repoName) config2 := config + ` data "github_repository_autolink_references" "all" { diff --git a/github/data_source_github_repository_branches_test.go b/github/data_source_github_repository_branches_test.go index 9689d0a725..55cfd86cbb 100644 --- a/github/data_source_github_repository_branches_test.go +++ b/github/data_source_github_repository_branches_test.go @@ -10,7 +10,7 @@ import ( func TestAccGithubRepositoryBranchesDataSource(t *testing.T) { t.Run("manages branches of a new repository", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-branches-%s", acctest.RandString(5)) + repoName := fmt.Sprintf("%srepo-branches-%s", testResourcePrefix, acctest.RandString(5)) config := fmt.Sprintf(` resource "github_repository" "test" { name = "%s" @@ -42,7 +42,7 @@ func TestAccGithubRepositoryBranchesDataSource(t *testing.T) { }) t.Run("manages branches of a new repository with filtering", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-branches-%s", acctest.RandString(5)) + repoName := fmt.Sprintf("%srepo-branches-%s", testResourcePrefix, acctest.RandString(5)) config := fmt.Sprintf(` resource "github_repository" "test" { name = "%s" diff --git a/github/data_source_github_repository_custom_properties_test.go b/github/data_source_github_repository_custom_properties_test.go index ade0bf4b03..29da0d447a 100644 --- a/github/data_source_github_repository_custom_properties_test.go +++ b/github/data_source_github_repository_custom_properties_test.go @@ -12,6 +12,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { t.Run("creates custom property of type single_select without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) + repoName := fmt.Sprintf("%srepo-custom-props-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_organization_custom_properties" "test" { @@ -21,7 +22,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { value_type = "single_select" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -33,7 +34,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { data "github_repository_custom_properties" "test" { repository = github_repository_custom_property.test.repository } - `, propertyName, randomID) + `, propertyName, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", "property.*", map[string]string{ @@ -58,6 +59,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { t.Run("creates custom property of type multi_select without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) + repoName := fmt.Sprintf("%srepo-custom-props-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_organization_custom_properties" "test" { @@ -67,7 +69,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { value_type = "multi_select" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -79,7 +81,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { data "github_repository_custom_properties" "test" { repository = github_repository_custom_property.test.repository } - `, propertyName, randomID) + `, propertyName, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", "property.*", map[string]string{ @@ -105,6 +107,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { t.Run("creates custom property of type true_false without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) + repoName := fmt.Sprintf("%srepo-custom-props-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_organization_custom_properties" "test" { @@ -113,7 +116,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { value_type = "true_false" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -125,7 +128,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { data "github_repository_custom_properties" "test" { repository = github_repository_custom_property.test.repository } - `, propertyName, randomID) + `, propertyName, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", "property.*", map[string]string{ @@ -150,6 +153,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { t.Run("creates custom property of type string without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) + repoName := fmt.Sprintf("%srepo-custom-props-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_organization_custom_properties" "test" { @@ -158,7 +162,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { value_type = "string" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -170,7 +174,7 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { data "github_repository_custom_properties" "test" { repository = github_repository_custom_property.test.repository } - `, propertyName, randomID) + `, propertyName, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", "property.*", map[string]string{ diff --git a/github/data_source_github_repository_deploy_keys_test.go b/github/data_source_github_repository_deploy_keys_test.go index e89052700a..dab6d610bd 100644 --- a/github/data_source_github_repository_deploy_keys_test.go +++ b/github/data_source_github_repository_deploy_keys_test.go @@ -22,7 +22,7 @@ func TestAccGithubRepositoryDeployKeysDataSource(t *testing.T) { keyPath := strings.ReplaceAll(filepath.Join("test-fixtures", fmt.Sprintf("%s.pub", keyName)), "\\", "/") - repoName := fmt.Sprintf("tf-acc-test-deploy-keys-%s", acctest.RandString(5)) + repoName := fmt.Sprintf("%srepo-deploy-keys-%s", testResourcePrefix, acctest.RandString(5)) config := fmt.Sprintf(` resource "github_repository" "test" { name = "%s" diff --git a/github/data_source_github_repository_deployment_branch_policies_test.go b/github/data_source_github_repository_deployment_branch_policies_test.go index 983b219801..2c1e1a251d 100644 --- a/github/data_source_github_repository_deployment_branch_policies_test.go +++ b/github/data_source_github_repository_deployment_branch_policies_test.go @@ -11,9 +11,10 @@ import ( func TestAccGithubRepositoryDeploymentBranchPolicies(t *testing.T) { t.Run("queries deployment branch policies", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-deploy-bp-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -31,7 +32,7 @@ func TestAccGithubRepositoryDeploymentBranchPolicies(t *testing.T) { environment_name = github_repository_environment.env.environment name = "foo" } - `, randomID) + `, repoName) config2 := config + ` data "github_repository_deployment_branch_policies" "all" { diff --git a/github/data_source_github_repository_environment_deployment_policies_test.go b/github/data_source_github_repository_environment_deployment_policies_test.go index 7395aaf84e..0e3c003c15 100644 --- a/github/data_source_github_repository_environment_deployment_policies_test.go +++ b/github/data_source_github_repository_environment_deployment_policies_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryEnvironmentDeploymentPolicies(t *testing.T) { t.Run("queries environment deployment policies", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-pol-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -45,7 +46,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicies(t *testing.T) { depends_on = [github_repository_environment_deployment_policy.branch, github_repository_environment_deployment_policy.tag] } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/data_source_github_repository_environments_test.go b/github/data_source_github_repository_environments_test.go index e1bc555581..e7171011a9 100644 --- a/github/data_source_github_repository_environments_test.go +++ b/github/data_source_github_repository_environments_test.go @@ -10,18 +10,19 @@ import ( func TestAccGithubRepositoryEnvironmentsDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-envs-%s", testResourcePrefix, randomID) t.Run("queries environments", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } resource "github_repository_environment" "env1" { repository = github_repository.test.name environment = "env_x" } - `, randomID) + `, repoName) config2 := config + ` data "github_repository_environments" "all" { diff --git a/github/data_source_github_repository_file_test.go b/github/data_source_github_repository_file_test.go index 1dd6ded9cb..27bba16c29 100644 --- a/github/data_source_github_repository_file_test.go +++ b/github/data_source_github_repository_file_test.go @@ -11,9 +11,10 @@ import ( func TestAccGithubRepositoryFileDataSource(t *testing.T) { t.Run("reads a file with a branch name provided without erroring", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true lifecycle { @@ -36,7 +37,7 @@ func TestAccGithubRepositoryFileDataSource(t *testing.T) { branch = "main" file = github_repository_file.test.file } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -61,7 +62,7 @@ func TestAccGithubRepositoryFileDataSource(t *testing.T) { t.Run("reads a file from a short repo name without erroring", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { name = "%s" @@ -114,10 +115,11 @@ func TestAccGithubRepositoryFileDataSource(t *testing.T) { t.Run("create and read a file without providing a branch name", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true lifecycle { @@ -139,7 +141,7 @@ func TestAccGithubRepositoryFileDataSource(t *testing.T) { repository = github_repository.test.name file = github_repository_file.test.file } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -206,9 +208,10 @@ func TestAccGithubRepositoryFileDataSource(t *testing.T) { t.Run("reads a directory without erroring", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true lifecycle { @@ -220,7 +223,7 @@ func TestAccGithubRepositoryFileDataSource(t *testing.T) { repository = github_repository.test.name file = "." } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/data_source_github_repository_milestone_test.go b/github/data_source_github_repository_milestone_test.go index 562f6b8333..485110d9d2 100644 --- a/github/data_source_github_repository_milestone_test.go +++ b/github/data_source_github_repository_milestone_test.go @@ -12,10 +12,11 @@ import ( func TestAccGithubRepositoryMilestoneDataSource(t *testing.T) { t.Run("queries a repository milestone", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-milestone-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_milestone" "test" { @@ -33,7 +34,7 @@ func TestAccGithubRepositoryMilestoneDataSource(t *testing.T) { number = github_repository_milestone.test.number } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/data_source_github_repository_pull_request_test.go b/github/data_source_github_repository_pull_request_test.go index 2568e15a84..bacdc008a1 100644 --- a/github/data_source_github_repository_pull_request_test.go +++ b/github/data_source_github_repository_pull_request_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryPullRequestDataSource(t *testing.T) { t.Run("manages the pull request lifecycle", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-pr-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -43,14 +44,14 @@ func TestAccGithubRepositoryPullRequestDataSource(t *testing.T) { base_repository = github_repository_pull_request.test.base_repository number = github_repository_pull_request.test.number } - `, randomID) + `, repoName) const resourceName = "data.github_repository_pull_request.test" check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( resourceName, "base_repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr(resourceName, "base_ref", "main"), resource.TestCheckResourceAttr(resourceName, "head_ref", "test"), diff --git a/github/data_source_github_repository_pull_requests_test.go b/github/data_source_github_repository_pull_requests_test.go index 69430b17ad..7bf4ce6098 100644 --- a/github/data_source_github_repository_pull_requests_test.go +++ b/github/data_source_github_repository_pull_requests_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryPullRequestsDataSource(t *testing.T) { t.Run("manages the pull request lifecycle", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-prs-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -47,12 +48,12 @@ func TestAccGithubRepositoryPullRequestsDataSource(t *testing.T) { sort_direction = "desc" state = "open" } - `, randomID) + `, repoName) const resourceName = "data.github_repository_pull_requests.test" check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "base_repository", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr(resourceName, "base_repository", repoName), resource.TestCheckResourceAttr(resourceName, "state", "open"), resource.TestCheckResourceAttr(resourceName, "base_ref", "main"), resource.TestCheckResourceAttr(resourceName, "head_ref", "test"), @@ -67,7 +68,7 @@ func TestAccGithubRepositoryPullRequestsDataSource(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "results.0.draft", "false"), resource.TestCheckResourceAttrSet(resourceName, "results.0.head_owner"), resource.TestCheckResourceAttr(resourceName, "results.0.head_ref", "test"), - resource.TestCheckResourceAttr(resourceName, "results.0.head_repository", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr(resourceName, "results.0.head_repository", repoName), resource.TestCheckResourceAttrSet(resourceName, "results.0.head_sha"), resource.TestCheckResourceAttr(resourceName, "results.0.labels.#", "0"), resource.TestCheckResourceAttr(resourceName, "results.0.maintainer_can_modify", "false"), diff --git a/github/data_source_github_repository_teams_test.go b/github/data_source_github_repository_teams_test.go index f7f1525325..4decdfd3a0 100644 --- a/github/data_source_github_repository_teams_test.go +++ b/github/data_source_github_repository_teams_test.go @@ -11,15 +11,17 @@ import ( func TestAccGithubRepositoryTeamsDataSource(t *testing.T) { t.Run("queries teams of an existing repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_team_repository" "test" { @@ -27,7 +29,7 @@ func TestAccGithubRepositoryTeamsDataSource(t *testing.T) { repository = github_repository.test.name permission = "push" } - `, randomID, randomID) + `, repoName, teamName) config2 := config + ` data "github_repository_teams" "test" { @@ -36,9 +38,9 @@ func TestAccGithubRepositoryTeamsDataSource(t *testing.T) { ` check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.github_repository_teams.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_repository_teams.test", "name", repoName), resource.TestCheckResourceAttr("data.github_repository_teams.test", "teams.#", "1"), - resource.TestCheckResourceAttr("data.github_repository_teams.test", "teams.0.slug", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_repository_teams.test", "teams.0.slug", teamName), resource.TestCheckResourceAttr("data.github_repository_teams.test", "teams.0.permission", "push"), ) diff --git a/github/data_source_github_repository_test.go b/github/data_source_github_repository_test.go index dc0f7b573f..c9d1e5aaf5 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -86,10 +86,11 @@ func TestAccDataSourceGithubRepository(t *testing.T) { t.Run("queries a repository with pages configured", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ds-pages-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" auto_init = true pages { source { @@ -101,7 +102,7 @@ func TestAccDataSourceGithubRepository(t *testing.T) { data "github_repository" "test" { name = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -124,7 +125,7 @@ func TestAccDataSourceGithubRepository(t *testing.T) { t.Run("checks defaults on a new repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-%s", randomID) + repoName := fmt.Sprintf("%srepo-ds-defaults-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` @@ -217,10 +218,11 @@ func TestAccDataSourceGithubRepository(t *testing.T) { t.Run("queries a repository that was generated from a template", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ds-template-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" template { owner = "%s" repository = "%s" @@ -230,7 +232,7 @@ func TestAccDataSourceGithubRepository(t *testing.T) { data "github_repository" "test" { name = github_repository.test.name } - `, randomID, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository) + `, repoName, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -257,16 +259,17 @@ func TestAccDataSourceGithubRepository(t *testing.T) { t.Run("queries a repository that has no primary_language", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ds-nolang-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" } data "github_repository" "test" { name = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -289,10 +292,11 @@ func TestAccDataSourceGithubRepository(t *testing.T) { // t.Run("queries a repository that has go as primary_language", func(t *testing.T) { // randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + // testResourceName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) // config := fmt.Sprintf(` // resource "github_repository" "test" { - // name = "tf-acc-%s" + // name = "%s" // auto_init = true // } // resource "github_repository_file" "test" { @@ -305,7 +309,7 @@ func TestAccDataSourceGithubRepository(t *testing.T) { // name = github_repository_file.test.repository // depends_on = [github_repository_file.test] // } - // `, randomID) + // `, testResourceName) // check := resource.ComposeTestCheckFunc( // resource.TestCheckResourceAttr("data.github_repository.test", "primary_language", "Go"), @@ -330,10 +334,11 @@ func TestAccDataSourceGithubRepository(t *testing.T) { t.Run("queries a repository that has a license", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ds-license-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" auto_init = true } resource "github_repository_file" "test" { @@ -354,7 +359,7 @@ EOT data "github_repository" "test" { name = github_repository_file.test.repository } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/data_source_github_repository_webhooks_test.go b/github/data_source_github_repository_webhooks_test.go index e14a687f40..da1dd83277 100644 --- a/github/data_source_github_repository_webhooks_test.go +++ b/github/data_source_github_repository_webhooks_test.go @@ -10,7 +10,7 @@ import ( func TestAccGithubRepositoryWebhooksDataSource(t *testing.T) { t.Run("manages repository webhooks", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-webhooks-%s", acctest.RandString(5)) + repoName := fmt.Sprintf("%srepo-webhooks-%s", testResourcePrefix, acctest.RandString(5)) config := fmt.Sprintf(` resource "github_repository" "test" { diff --git a/github/data_source_github_rest_api_test.go b/github/data_source_github_rest_api_test.go index 8469394ab8..030d2d7865 100644 --- a/github/data_source_github_rest_api_test.go +++ b/github/data_source_github_rest_api_test.go @@ -11,18 +11,19 @@ import ( func TestAccGithubRestApiDataSource(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-rest-api-%s", testResourcePrefix, randomID) t.Run("queries an existing branch without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_rest_api" "test" { endpoint = "repos/${github_repository.test.full_name}/git/refs/heads/${github_repository.test.default_branch}" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr( @@ -50,14 +51,14 @@ func TestAccGithubRestApiDataSource(t *testing.T) { t.Run("queries a collection without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_rest_api" "test" { endpoint = "repos/${github_repository.test.full_name}/git/refs/heads/" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr("data.github_rest_api.test", "body", regexp.MustCompile(`\[.*refs/heads/.*\]`)), @@ -78,14 +79,14 @@ func TestAccGithubRestApiDataSource(t *testing.T) { t.Run("queries an invalid branch without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } data "github_rest_api" "test" { endpoint = "repos/${github_repository.test.full_name}/git/refs/heads/xxxxxx" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr( diff --git a/github/data_source_github_team_test.go b/github/data_source_github_team_test.go index 4c4c6326f5..7967a26ec6 100644 --- a/github/data_source_github_team_test.go +++ b/github/data_source_github_team_test.go @@ -12,15 +12,16 @@ import ( func TestAccGithubTeamDataSource(t *testing.T) { t.Run("queries an existing team without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_team" "test" { slug = github_team.test.slug } - `, randomID) + `, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.github_team.test", "name"), @@ -43,20 +44,21 @@ func TestAccGithubTeamDataSource(t *testing.T) { t.Run("queries an existing team without error with immediate membership", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_team" "test" { slug = github_team.test.slug membership_type = "immediate" } - `, randomID) + `, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.github_team.test", "name"), - resource.TestCheckResourceAttr("data.github_team.test", "name", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("data.github_team.test", "name", teamName), ) resource.Test(t, resource.TestCase{ @@ -92,16 +94,17 @@ func TestAccGithubTeamDataSource(t *testing.T) { t.Run("queries an existing team without error in summary_only mode", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_team" "test" { slug = github_team.test.slug summary_only = true } - `, randomID) + `, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.github_team.test", "name"), @@ -126,16 +129,17 @@ func TestAccGithubTeamDataSource(t *testing.T) { t.Run("queries an existing team without error with results_per_page reduced", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_team" "test" { slug = github_team.test.slug results_per_page = 20 } - `, randomID) + `, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.github_team.test", "name"), @@ -156,14 +160,16 @@ func TestAccGithubTeamDataSource(t *testing.T) { t.Run("get team with repositories without erroring", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%s" } resource "github_team_repository" "test" { @@ -177,7 +183,7 @@ func TestAccGithubTeamDataSource(t *testing.T) { depends_on = [github_repository.test, github_team.test, github_team_repository.test] } - `, randomID) + `, repoName, teamName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -208,19 +214,21 @@ func TestAccGithubTeamDataSource(t *testing.T) { t.Run("queries an existing team with connected repositories", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository" "test" { - name = "tf-acc-test" + name = "%s" } resource "github_team_repository" "test" { team_id = github_team.test.id repository = github_repository.test.name permission = "admin" } - `, randomID) + `, teamName, repoName) config2 := config + ` data "github_team" "test" { @@ -230,7 +238,7 @@ func TestAccGithubTeamDataSource(t *testing.T) { check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.github_team.test", "name"), - resource.TestCheckResourceAttr("github_repository.test", "name", "tf-acc-test"), + resource.TestCheckResourceAttr("github_repository.test", "name", repoName), resource.TestCheckResourceAttr("data.github_team.test", "repositories_detailed.#", "1"), resource.TestCheckResourceAttrPair("data.github_team.test", "repositories_detailed.0.repo_id", "github_repository.test", "repo_id"), resource.TestCheckResourceAttrPair("data.github_team.test", "repositories_detailed.0.repo_name", "github_repository.test", "name"), diff --git a/github/data_source_github_tree_test.go b/github/data_source_github_tree_test.go index 25fb86818d..394c079fb6 100644 --- a/github/data_source_github_tree_test.go +++ b/github/data_source_github_tree_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubTreeDataSource(t *testing.T) { t.Run("get tree", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-tree-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "this" { auto_init = true - name = "tf-acc-test-%s" + name = "%s" } data "github_branch" "this" { @@ -27,7 +28,7 @@ func TestAccGithubTreeDataSource(t *testing.T) { repository = github_repository.this.name tree_sha = data.github_branch.this.sha } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/resource_github_actions_environment_secret_test.go b/github/resource_github_actions_environment_secret_test.go index 00e4f5a6df..3164547ae4 100644 --- a/github/resource_github_actions_environment_secret_test.go +++ b/github/resource_github_actions_environment_secret_test.go @@ -14,12 +14,13 @@ import ( func TestAccGithubActionsEnvironmentSecret(t *testing.T) { t.Run("creates and updates secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-env-secret-%s", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) updatedSecretValue := base64.StdEncoding.EncodeToString([]byte("updated_super_secret_value")) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_environment" "test" { @@ -40,7 +41,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) { secret_name = "test_encrypted_secret_name" encrypted_value = "%s" } - `, randomID, secretValue, secretValue) + `, repoName, secretValue, secretValue) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -97,11 +98,12 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) { t.Run("deletes secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-env-secret-%s", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_environment" "test" { @@ -122,7 +124,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) { secret_name = "test_encrypted_secret_name" encrypted_value = "%s" } - `, randomID, secretValue, secretValue) + `, repoName, secretValue, secretValue) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -139,6 +141,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) { func TestAccGithubActionsEnvironmentSecretIgnoreChanges(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-env-secret-ic-%s", testResourcePrefix, randomID) t.Run("creates environment secrets using lifecycle ignore_changes", func(t *testing.T) { secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) @@ -146,7 +149,7 @@ func TestAccGithubActionsEnvironmentSecretIgnoreChanges(t *testing.T) { configFmtStr := ` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" # TODO: provider appears to have issues destroying repositories while running the tests. # @@ -227,18 +230,18 @@ func TestAccGithubActionsEnvironmentSecretIgnoreChanges(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(configFmtStr, randomID, secretValue, secretValue), + Config: fmt.Sprintf(configFmtStr, repoName, secretValue, secretValue), Check: checks["before"], }, { - Config: fmt.Sprintf(configFmtStr, randomID, secretValue, secretValue), + Config: fmt.Sprintf(configFmtStr, repoName, secretValue, secretValue), Check: checks["after"], }, { // In this case the values change in the config, but the lifecycle ignore_changes should // not cause the actual values to be updated. This would also be the case when a secret // is externally modified (when what is in state does not match what is given). - Config: fmt.Sprintf(configFmtStr, randomID, modifiedSecretValue, modifiedSecretValue), + Config: fmt.Sprintf(configFmtStr, repoName, modifiedSecretValue, modifiedSecretValue), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_actions_environment_secret.plaintext_secret", "plaintext_value", diff --git a/github/resource_github_actions_environment_variable_test.go b/github/resource_github_actions_environment_variable_test.go index 3faa553dc0..2a2325eacc 100644 --- a/github/resource_github_actions_environment_variable_test.go +++ b/github/resource_github_actions_environment_variable_test.go @@ -16,12 +16,13 @@ import ( func TestAccGithubActionsEnvironmentVariable(t *testing.T) { t.Run("creates and updates environment variables without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-env-var-%s", testResourcePrefix, randomID) value := "my_variable_value" updatedValue := "my_updated_variable_value" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_environment" "test" { @@ -35,7 +36,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { variable_name = "test_variable" value = "%s" } - `, randomID, value) + `, repoName, value) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -84,9 +85,10 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { t.Run("deletes environment variables without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-env-var-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_environment" "test" { @@ -100,7 +102,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { variable_name = "test_variable" value = "my_variable_value" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -116,13 +118,14 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { t.Run("imports environment variables without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-env-var-%s", testResourcePrefix, randomID) value := "my_variable_value" envName := "environment / test" varName := "test_variable" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_environment" "test" { @@ -136,7 +139,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { variable_name = "%s" value = "%s" } - `, randomID, envName, varName, value) + `, repoName, envName, varName, value) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -147,7 +150,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { }, { ResourceName: "github_actions_environment_variable.variable", - ImportStateId: fmt.Sprintf(`tf-acc-test-%s:%s:%s`, randomID, envName, varName), + ImportStateId: fmt.Sprintf(`%s:%s:%s`, repoName, envName, varName), ImportState: true, ImportStateVerify: true, }, @@ -158,7 +161,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) { func TestAccGithubActionsEnvironmentVariable_alreadyExists(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) + repoName := fmt.Sprintf("%srepo-act-env-var-exist-%s", testResourcePrefix, randomID) envName := "environment / test" varName := "test_variable" value := "my_variable_value" diff --git a/github/resource_github_actions_organization_permissions_test.go b/github/resource_github_actions_organization_permissions_test.go index 0197a83463..4fa46ecba2 100644 --- a/github/resource_github_actions_organization_permissions_test.go +++ b/github/resource_github_actions_organization_permissions_test.go @@ -47,10 +47,11 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) { githubOwnedAllowed := true verifiedAllowed := true randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-org-perm-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -67,7 +68,7 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) { repository_ids = [github_repository.test.repo_id] } } - `, randomID, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed) + `, repoName, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -187,16 +188,18 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) { verifiedAllowed := true randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) randomID2 := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-org-perm-%s", testResourcePrefix, randomID) + repoName2 := fmt.Sprintf("%srepo-act-org-perm-%s", testResourcePrefix, randomID2) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } resource "github_repository" "test2" { - name = "tf-acc-test-topic-%[2]s" + name = "%[2]s" description = "Terraform acceptance tests %[2]s" topics = ["terraform", "testing"] } @@ -208,7 +211,7 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) { repository_ids = [github_repository.test.repo_id, github_repository.test2.repo_id] } } - `, randomID, randomID2, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed) + `, repoName, repoName2, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_actions_organization_secret_repositories_test.go b/github/resource_github_actions_organization_secret_repositories_test.go index 4adf359826..dd37037d5d 100644 --- a/github/resource_github_actions_organization_secret_repositories_test.go +++ b/github/resource_github_actions_organization_secret_repositories_test.go @@ -2,7 +2,6 @@ package github import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -10,24 +9,24 @@ import ( ) func TestAccGithubActionsOrganizationSecretRepositories(t *testing.T) { - const ORG_SECRET_NAME = "ORG_SECRET_NAME" randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - secret_name, exists := os.LookupEnv(ORG_SECRET_NAME) + repoName1 := fmt.Sprintf("%srepo-act-org-secret-%s-1", testResourcePrefix, randomID) + repoName2 := fmt.Sprintf("%srepo-act-org-secret-%s-2", testResourcePrefix, randomID) t.Run("set repository allowlist for a organization secret", func(t *testing.T) { - if !exists { - t.Skipf("%s environment variable is missing", ORG_SECRET_NAME) + if len(testAccConf.testOrgSecretName) == 0 { + t.Skipf("'GH_TEST_ORG_SECRET_NAME' environment variable is missing") } config := fmt.Sprintf(` resource "github_repository" "test_repo_1" { - name = "tf-acc-test-%s-1" + name = "%s" visibility = "internal" vulnerability_alerts = "true" } resource "github_repository" "test_repo_2" { - name = "tf-acc-test-%s-2" + name = "%s" visibility = "internal" vulnerability_alerts = "true" } @@ -39,7 +38,7 @@ func TestAccGithubActionsOrganizationSecretRepositories(t *testing.T) { github_repository.test_repo_2.repo_id ] } - `, randomID, randomID, secret_name) + `, repoName1, repoName2, testAccConf.testOrgSecretName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/resource_github_actions_organization_secret_repository_test.go b/github/resource_github_actions_organization_secret_repository_test.go index ab6465feac..c8e1533e8c 100644 --- a/github/resource_github_actions_organization_secret_repository_test.go +++ b/github/resource_github_actions_organization_secret_repository_test.go @@ -11,6 +11,7 @@ import ( func TestAccGithubActionsOrganizationSecretRepository(t *testing.T) { t.Run("set repository allowlist for a organization secret", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-org-secret-%s", testResourcePrefix, randomID) secretName := testAccConf.testOrgSecretName if len(secretName) == 0 { t.Skip("test organization secret name is not set") @@ -18,7 +19,7 @@ func TestAccGithubActionsOrganizationSecretRepository(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test_repo_1" { - name = "tf-acc-test-%s-1" + name = "%s" visibility = "internal" vulnerability_alerts = "true" } @@ -27,7 +28,7 @@ func TestAccGithubActionsOrganizationSecretRepository(t *testing.T) { secret_name = "%s" repository_id = github_repository.test_repo_1.repo_id } - `, randomID, secretName) + `, repoName, secretName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/resource_github_actions_organization_variable_test.go b/github/resource_github_actions_organization_variable_test.go index 408cbe5db4..52ac31fb21 100644 --- a/github/resource_github_actions_organization_variable_test.go +++ b/github/resource_github_actions_organization_variable_test.go @@ -74,10 +74,11 @@ func TestAccGithubActionsOrganizationVariable(t *testing.T) { t.Run("creates an organization variable scoped to a repo without error", func(t *testing.T) { value := "my_variable_value" randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-org-var-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_organization_variable" "variable" { @@ -86,7 +87,7 @@ func TestAccGithubActionsOrganizationVariable(t *testing.T) { visibility = "selected" selected_repository_ids = [github_repository.test.repo_id] } - `, randomID, value) + `, repoName, value) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( diff --git a/github/resource_github_actions_repository_access_level_test.go b/github/resource_github_actions_repository_access_level_test.go index 884c8c7d50..2661cc2dba 100644 --- a/github/resource_github_actions_repository_access_level_test.go +++ b/github/resource_github_actions_repository_access_level_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubActionsRepositoryAccessLevel(t *testing.T) { t.Run("test setting of user action access level", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-access-%s", testResourcePrefix, randomID) accessLevel := "user" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] visibility = "private" @@ -24,7 +25,7 @@ func TestAccGithubActionsRepositoryAccessLevel(t *testing.T) { access_level = "%s" repository = github_repository.test.name } - `, randomID, accessLevel) + `, repoName, accessLevel) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -46,10 +47,11 @@ func TestAccGithubActionsRepositoryAccessLevel(t *testing.T) { t.Run("test setting of organization action access level", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-access-%s", testResourcePrefix, randomID) accessLevel := "organization" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] visibility = "private" @@ -59,7 +61,7 @@ func TestAccGithubActionsRepositoryAccessLevel(t *testing.T) { access_level = "%s" repository = github_repository.test.name } - `, randomID, accessLevel) + `, repoName, accessLevel) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_actions_repository_oidc_subject_claim_customization_template_test.go b/github/resource_github_actions_repository_oidc_subject_claim_customization_template_test.go index 3dc17e14c0..ed29828432 100644 --- a/github/resource_github_actions_repository_oidc_subject_claim_customization_template_test.go +++ b/github/resource_github_actions_repository_oidc_subject_claim_customization_template_test.go @@ -11,9 +11,10 @@ import ( func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate(t *testing.T) { t.Run("creates repository oidc subject claim customization template without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-oidc-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" } @@ -21,7 +22,7 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate(t *test repository = github_repository.test.name use_default = false include_claim_keys = ["repo", "context", "job_workflow_ref"] - }`, randomID) + }`, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -58,9 +59,10 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate(t *test t.Run("updates repository oidc subject claim customization template without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-oidc-%s", testResourcePrefix, randomID) configTemplate := ` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" } @@ -75,7 +77,7 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate(t *test resetToDefaultConfigTemplate := ` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" } @@ -86,11 +88,11 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate(t *test ` configs := map[string]string{ - "before": fmt.Sprintf(configTemplate, randomID, false, claims), + "before": fmt.Sprintf(configTemplate, repoName, false, claims), - "after": fmt.Sprintf(configTemplate, randomID, false, updatedClaims), + "after": fmt.Sprintf(configTemplate, repoName, false, updatedClaims), - "reset_to_default": fmt.Sprintf(resetToDefaultConfigTemplate, randomID), + "reset_to_default": fmt.Sprintf(resetToDefaultConfigTemplate, repoName), } checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -171,16 +173,17 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate(t *test t.Run("imports repository oidc subject claim customization template without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-oidc-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" } resource "github_actions_repository_oidc_subject_claim_customization_template" "test" { repository = github_repository.test.name use_default = false include_claim_keys = ["repository_owner_id", "run_id", "workflow"] - }`, randomID) + }`, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_actions_repository_permissions_test.go b/github/resource_github_actions_repository_permissions_test.go index 9ab8191ca2..a04f556aab 100644 --- a/github/resource_github_actions_repository_permissions_test.go +++ b/github/resource_github_actions_repository_permissions_test.go @@ -12,10 +12,11 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { t.Run("test setting of basic actions repository permissions", func(t *testing.T) { allowedActions := "local_only" randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -24,7 +25,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { allowed_actions = "%s" repository = github_repository.test.name } - `, randomID, allowedActions) + `, repoName, allowedActions) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -49,10 +50,11 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { githubOwnedAllowed := true verifiedAllowed := true randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -66,7 +68,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { } repository = github_repository.test.name } - `, randomID, allowedActions, githubOwnedAllowed, verifiedAllowed) + `, repoName, allowedActions, githubOwnedAllowed, verifiedAllowed) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -99,10 +101,11 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { githubOwnedAllowed := true verifiedAllowed := true randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -116,7 +119,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { } repository = github_repository.test.name } - `, randomID, allowedActions, githubOwnedAllowed, verifiedAllowed) + `, repoName, allowedActions, githubOwnedAllowed, verifiedAllowed) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -142,10 +145,11 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { t.Run("test not setting of repository allowed actions without error", func(t *testing.T) { allowedActions := "selected" randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -154,7 +158,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { allowed_actions = "%s" repository = github_repository.test.name } - `, randomID, allowedActions) + `, repoName, allowedActions) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -182,10 +186,11 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { t.Run("test disabling actions on a repository", func(t *testing.T) { actionsEnabled := false randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -194,7 +199,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { enabled = %t repository = github_repository.test.name } - `, randomID, actionsEnabled) + `, repoName, actionsEnabled) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -217,6 +222,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { // https://github.com/integrations/terraform-provider-github/issues/2182 t.Run("test load with disabled actions", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` locals { @@ -224,7 +230,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-actions-permissions-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -234,7 +240,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) { enabled = local.actions_enabled allowed_actions = local.actions_enabled ? "all" : null } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_actions_runner_group_test.go b/github/resource_github_actions_runner_group_test.go index 170b7402fa..094897739b 100644 --- a/github/resource_github_actions_runner_group_test.go +++ b/github/resource_github_actions_runner_group_test.go @@ -14,9 +14,10 @@ import ( func TestAccGithubActionsRunnerGroup(t *testing.T) { t.Run("creates runner groups without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-runner-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" vulnerability_alerts = false auto_init = true } @@ -41,7 +42,7 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { selected_workflows = ["${github_repository.test.full_name}/.github/workflows/test.yml@refs/heads/main"] allows_public_repositories = true } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( @@ -49,7 +50,7 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { ), resource.TestCheckResourceAttr( "github_actions_runner_group.test", "name", - fmt.Sprintf(`tf-acc-test-%s`, randomID), + repoName, ), resource.TestCheckResourceAttr( "github_actions_runner_group.test", "visibility", @@ -98,9 +99,10 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { t.Run("manages runner visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-runner-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_runner_group" "test" { @@ -108,7 +110,7 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { visibility = "selected" selected_repository_ids = [github_repository.test.repo_id] } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( @@ -116,7 +118,7 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { ), resource.TestCheckResourceAttr( "github_actions_runner_group.test", "name", - fmt.Sprintf(`tf-acc-test-%s`, randomID), + repoName, ), resource.TestCheckResourceAttr( "github_actions_runner_group.test", "visibility", @@ -145,22 +147,23 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { t.Run("imports an all runner group without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-runner-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_runner_group" "test" { name = github_repository.test.name visibility = "all" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_actions_runner_group.test", "name"), resource.TestCheckResourceAttrSet("github_actions_runner_group.test", "visibility"), resource.TestCheckResourceAttr("github_actions_runner_group.test", "visibility", "all"), - resource.TestCheckResourceAttr("github_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, randomID)), + resource.TestCheckResourceAttr("github_actions_runner_group.test", "name", repoName), ) resource.Test(t, resource.TestCase{ @@ -184,23 +187,25 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { // Note: this test is skipped because when setting visibility 'private', it always fails with: // Step 0 error: After applying this step, the plan was not empty: // visibility: "all" => "private" + // Based on GitHub UI there is no way to create a private runner group t.Skip("This is not supported") randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-runner-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_runner_group" "test" { name = github_repository.test.name visibility = "private" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_actions_runner_group.test", "name"), - resource.TestCheckResourceAttr("github_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, randomID)), + resource.TestCheckResourceAttr("github_actions_runner_group.test", "name", repoName), resource.TestCheckResourceAttrSet("github_actions_runner_group.test", "visibility"), ) @@ -223,9 +228,10 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { t.Run("imports a selected runner group without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-runner-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_runner_group" "test" { @@ -233,11 +239,11 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { visibility = "selected" selected_repository_ids = [github_repository.test.repo_id] } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_actions_runner_group.test", "name"), - resource.TestCheckResourceAttr("github_actions_runner_group.test", "name", fmt.Sprintf(`tf-acc-test-%s`, randomID)), + resource.TestCheckResourceAttr("github_actions_runner_group.test", "name", repoName), resource.TestCheckResourceAttrSet("github_actions_runner_group.test", "visibility"), resource.TestCheckResourceAttr("github_actions_runner_group.test", "visibility", "selected"), resource.TestCheckResourceAttr( diff --git a/github/resource_github_actions_secret_test.go b/github/resource_github_actions_secret_test.go index 82fb725e5c..3ea8ef697f 100644 --- a/github/resource_github_actions_secret_test.go +++ b/github/resource_github_actions_secret_test.go @@ -14,16 +14,17 @@ import ( func TestAccGithubActionsSecret(t *testing.T) { t.Run("reads a repository public key without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-secret-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_actions_public_key" "test_pk" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet( @@ -48,12 +49,13 @@ func TestAccGithubActionsSecret(t *testing.T) { t.Run("creates and updates secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-secret-%s", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) updatedSecretValue := base64.StdEncoding.EncodeToString([]byte("updated_super_secret_value")) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_secret" "plaintext_secret" { @@ -67,7 +69,7 @@ func TestAccGithubActionsSecret(t *testing.T) { secret_name = "test_encrypted_secret" encrypted_value = "%s" } - `, randomID, secretValue, secretValue) + `, repoName, secretValue, secretValue) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -124,8 +126,8 @@ func TestAccGithubActionsSecret(t *testing.T) { t.Run("creates and updates repository name without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) - updatedRepoName := fmt.Sprintf("tf-acc-test-%s-updated", randomID) + repoName := fmt.Sprintf("%srepo-act-secret-%s", testResourcePrefix, randomID) + updatedRepoName := fmt.Sprintf("%srepo-act-secret-%s-upd", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) config := fmt.Sprintf(` @@ -209,9 +211,10 @@ func TestAccGithubActionsSecret(t *testing.T) { t.Run("deletes secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-secret-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_secret" "plaintext_secret" { @@ -223,7 +226,7 @@ func TestAccGithubActionsSecret(t *testing.T) { repository = github_repository.test.name secret_name = "test_encrypted_secret" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -239,10 +242,11 @@ func TestAccGithubActionsSecret(t *testing.T) { t.Run("respects destroy_on_drift setting", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-secret-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_secret" "with_drift_true" { @@ -265,7 +269,7 @@ func TestAccGithubActionsSecret(t *testing.T) { plaintext_value = "initial_value" # destroy_on_drift defaults to true } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_actions_variable_test.go b/github/resource_github_actions_variable_test.go index f5d7230b22..f08ed44e6d 100644 --- a/github/resource_github_actions_variable_test.go +++ b/github/resource_github_actions_variable_test.go @@ -13,12 +13,13 @@ import ( func TestAccGithubActionsVariable(t *testing.T) { t.Run("creates and updates repository variables without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-var-%s", testResourcePrefix, randomID) value := "my_variable_value" updatedValue := "my_updated_variable_value" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_variable" "variable" { @@ -26,7 +27,7 @@ func TestAccGithubActionsVariable(t *testing.T) { variable_name = "test_variable" value = "%s" } - `, randomID, value) + `, repoName, value) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -75,9 +76,10 @@ func TestAccGithubActionsVariable(t *testing.T) { t.Run("deletes repository variables without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-var-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_variable" "variable" { @@ -85,7 +87,7 @@ func TestAccGithubActionsVariable(t *testing.T) { variable_name = "test_variable" value = "my_variable_value" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -101,12 +103,13 @@ func TestAccGithubActionsVariable(t *testing.T) { t.Run("imports repository variables without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-act-var-%s", testResourcePrefix, randomID) varName := "test_variable" value := "variable_value" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_actions_variable" "variable" { @@ -114,7 +117,7 @@ func TestAccGithubActionsVariable(t *testing.T) { variable_name = "%s" value = "%s" } - `, randomID, varName, value) + `, repoName, varName, value) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -125,7 +128,7 @@ func TestAccGithubActionsVariable(t *testing.T) { }, { ResourceName: "github_actions_variable.variable", - ImportStateId: fmt.Sprintf(`tf-acc-test-%s:%s`, randomID, varName), + ImportStateId: fmt.Sprintf(`%s:%s`, repoName, varName), ImportState: true, ImportStateVerify: true, }, diff --git a/github/resource_github_app_installation_repositories_test.go b/github/resource_github_app_installation_repositories_test.go index 80ff60342d..8c07b8f13a 100644 --- a/github/resource_github_app_installation_repositories_test.go +++ b/github/resource_github_app_installation_repositories_test.go @@ -15,9 +15,9 @@ func TestAccGithubAppInstallationRepositories(t *testing.T) { } t.Run("installs an app to multiple repositories", func(t *testing.T) { - randomId := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName0 := fmt.Sprintf("tf-acc-test-0-%s", randomId) - repoName1 := fmt.Sprintf("tf-acc-test-1-%s", randomId) + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName0 := fmt.Sprintf("%srepo-app-install-0-%s", testResourcePrefix, randomID) + repoName1 := fmt.Sprintf("%srepo-app-install-1-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test_0" { @@ -26,7 +26,7 @@ func TestAccGithubAppInstallationRepositories(t *testing.T) { } resource "github_repository" "test_1" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } diff --git a/github/resource_github_app_installation_repository_test.go b/github/resource_github_app_installation_repository_test.go index 3c1f524f06..70954a02e4 100644 --- a/github/resource_github_app_installation_repository_test.go +++ b/github/resource_github_app_installation_repository_test.go @@ -16,10 +16,12 @@ func TestAccGithubAppInstallationRepository(t *testing.T) { t.Run("installs an app to a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-app-install-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -29,7 +31,7 @@ func TestAccGithubAppInstallationRepository(t *testing.T) { repository = github_repository.test.name } - `, randomID, testAccConf.testOrgAppInstallationId) + `, repoName, testAccConf.testOrgAppInstallationId) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( diff --git a/github/resource_github_branch_default_test.go b/github/resource_github_branch_default_test.go index 1795ea267e..ba9e1550a8 100644 --- a/github/resource_github_branch_default_test.go +++ b/github/resource_github_branch_default_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubBranchDefault(t *testing.T) { t.Run("creates and manages branch defaults", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-def-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -22,7 +23,7 @@ func TestAccGithubBranchDefault(t *testing.T) { repository = github_repository.test.name branch = "main" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -31,7 +32,7 @@ func TestAccGithubBranchDefault(t *testing.T) { ), resource.TestCheckResourceAttr( "github_branch_default.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), ) @@ -49,9 +50,10 @@ func TestAccGithubBranchDefault(t *testing.T) { t.Run("replaces the default_branch of a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-def-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -65,7 +67,7 @@ func TestAccGithubBranchDefault(t *testing.T) { branch = github_branch.test.branch } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -96,9 +98,10 @@ func TestAccGithubBranchDefault(t *testing.T) { t.Run("creates and manages branch defaults even if rename is set", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-def-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -107,7 +110,7 @@ func TestAccGithubBranchDefault(t *testing.T) { branch = "main" rename = true } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -116,7 +119,7 @@ func TestAccGithubBranchDefault(t *testing.T) { ), resource.TestCheckResourceAttr( "github_branch_default.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), ) @@ -134,9 +137,10 @@ func TestAccGithubBranchDefault(t *testing.T) { t.Run("replaces the default_branch of a repository without creating a branch resource prior to", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-def-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -145,7 +149,7 @@ func TestAccGithubBranchDefault(t *testing.T) { branch = "development" rename = true } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_branch_protection_test.go b/github/resource_github_branch_protection_test.go index 4a03630305..a45cd47927 100644 --- a/github/resource_github_branch_protection_test.go +++ b/github/resource_github_branch_protection_test.go @@ -16,10 +16,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures default settings when empty", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -30,7 +31,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -69,7 +70,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateIdFunc: importBranchProtectionByRepoName( - fmt.Sprintf("tf-acc-test-%s", randomID), "main", + testRepoName, "main", ), }, { @@ -79,7 +80,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { `could not find a branch protection rule with the pattern 'no-such-pattern'`, ), ImportStateIdFunc: importBranchProtectionByRepoName( - fmt.Sprintf("tf-acc-test-%s", randomID), "no-such-pattern", + testRepoName, "no-such-pattern", ), }, }, @@ -88,11 +89,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures default settings when conversation resolution is true", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -104,7 +105,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { require_conversation_resolution = true } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -146,7 +147,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { ImportState: true, ImportStateVerify: true, ImportStateIdFunc: importBranchProtectionByRepoName( - fmt.Sprintf("tf-acc-test-%s", randomID), "main", + testRepoName, "main", ), }, { @@ -156,7 +157,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { `could not find a branch protection rule with the pattern 'no-such-pattern'`, ), ImportStateIdFunc: importBranchProtectionByRepoName( - fmt.Sprintf("tf-acc-test-%s", randomID), "no-such-pattern", + testRepoName, "no-such-pattern", ), }, }, @@ -165,11 +166,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures required status checks", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -185,7 +186,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -223,11 +224,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures required pull request reviews", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -244,7 +245,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -278,10 +279,10 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures branch push restrictions", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -292,7 +293,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { restrict_pushes {} } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -320,10 +321,10 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures branch push restrictions with node_id", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -342,7 +343,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { ] } } - `, randomID, testAccConf.username) + `, testRepoName, testAccConf.username) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -370,10 +371,10 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures branch push restrictions with username", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -388,7 +389,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { ] } } - `, randomID, testAccConf.username) + `, testRepoName, testAccConf.username) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -416,10 +417,10 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures branch push restrictions with blocksCreations false", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -432,7 +433,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { blocks_creations = false } } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -460,10 +461,10 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures force pushes and deletions", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -480,7 +481,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { allows_force_pushes = true } - `, randomID, testAccConf.username) + `, testRepoName, testAccConf.username) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -505,11 +506,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures non-empty list of force push bypassers", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -528,7 +529,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID, testAccConf.username) + `, testRepoName, testAccConf.username) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -550,16 +551,17 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures allow force push with a team as bypasser", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + teamName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) + repoName := teamName config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_team_repository" "test" { @@ -577,7 +579,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { ] } - `, randomID, randomID, testAccConf.owner) + `, repoName, teamName, testAccConf.owner) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -602,11 +604,12 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures empty list of force push bypassers", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -619,7 +622,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -641,11 +644,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures non-empty list of pull request bypassers", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -662,7 +665,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID, testAccConf.username) + `, testRepoName, testAccConf.username) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -684,11 +687,11 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { t.Run("configures empty list of pull request bypassers", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -703,7 +706,7 @@ func TestAccGithubBranchProtectionV4(t *testing.T) { } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_branch_protection_v3_test.go b/github/resource_github_branch_protection_v3_test.go index 8e892fb667..3d7dd28393 100644 --- a/github/resource_github_branch_protection_v3_test.go +++ b/github/resource_github_branch_protection_v3_test.go @@ -10,17 +10,18 @@ import ( func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) t.Run("configures required pull request reviews", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%s" } resource "github_team_repository" "test" { @@ -31,27 +32,27 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T) resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" - - required_pull_request_reviews { - dismiss_stale_reviews = true - require_code_owner_reviews = true - required_approving_review_count = 1 - require_last_push_approval = true - dismissal_users = ["a"] - dismissal_teams = ["b"] - dismissal_apps = ["c"] - bypass_pull_request_allowances { - users = ["d"] - teams = [github_team.test.slug] - apps = ["e"] - } - } - - depends_on = [github_team_repository.test] + repository = github_repository.test.name + branch = "main" + + required_pull_request_reviews { + dismiss_stale_reviews = true + require_code_owner_reviews = true + required_approving_review_count = 1 + require_last_push_approval = true + dismissal_users = ["a"] + dismissal_teams = ["b"] + dismissal_apps = ["c"] + bypass_pull_request_allowances { + users = ["d"] + teams = [github_team.test.slug] + apps = ["e"] + } + } + + depends_on = [github_team_repository.test] } - `, randomID) + `, repoName, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -107,17 +108,18 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T) func TestAccGithubBranchProtectionV3RequiredPullRequestReviewsBypassAllowances(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) t.Run("configures required pull request reviews with bypass allowances", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%s" } resource "github_team_repository" "test" { @@ -127,19 +129,19 @@ func TestAccGithubBranchProtectionV3RequiredPullRequestReviewsBypassAllowances(t } resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" + repository = github_repository.test.name + branch = "main" - required_pull_request_reviews { + required_pull_request_reviews { bypass_pull_request_allowances { teams = [github_team.test.slug] } - } + } depends_on = [github_team_repository.test] } - `, randomID) + `, repoName, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -165,16 +167,17 @@ func TestAccGithubBranchProtectionV3RequiredPullRequestReviewsBypassAllowances(t func TestAccGithubBranchProtectionV3_branch_push_restrictions(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) t.Run("configures branch push restrictions", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%s" } resource "github_team_repository" "test" { @@ -185,15 +188,15 @@ func TestAccGithubBranchProtectionV3_branch_push_restrictions(t *testing.T) { resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" + repository = github_repository.test.name + branch = "main" - restrictions { + restrictions { teams = ["${github_team.test.slug}"] - } + } } - `, randomID) + `, repoName, teamName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -215,12 +218,13 @@ func TestAccGithubBranchProtectionV3_branch_push_restrictions(t *testing.T) { } func TestAccGithubBranchProtectionV3_computed_status_checks_no_churn(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("handles computed status checks without churn", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -236,7 +240,7 @@ func TestAccGithubBranchProtectionV3_computed_status_checks_no_churn(t *testing. ] } } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -276,12 +280,12 @@ func TestAccGithubBranchProtectionV3_computed_status_checks_no_churn(t *testing. } func TestAccGithubBranchProtectionV3_computed_status_contexts_no_churn(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("handles computed status contexts without churn", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -297,7 +301,7 @@ func TestAccGithubBranchProtectionV3_computed_status_contexts_no_churn(t *testin ] } } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -339,19 +343,20 @@ func TestAccGithubBranchProtectionV3_computed_status_contexts_no_churn(t *testin func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures default settings when empty", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" + repository = github_repository.test.name + branch = "main" } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -374,20 +379,21 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures conversation resolution", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" + repository = github_repository.test.name + branch = "main" - require_conversation_resolution = true + require_conversation_resolution = true } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -410,9 +416,10 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures required status checks", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -430,7 +437,7 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { } } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -452,9 +459,10 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures required status checks context", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -467,7 +475,7 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { contexts = ["github/foo"] } } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -489,15 +497,16 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures required pull request reviews", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" } resource "github_team_repository" "test" { @@ -508,27 +517,27 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" - - required_pull_request_reviews { - dismiss_stale_reviews = true - require_code_owner_reviews = true - required_approving_review_count = 1 - require_last_push_approval = true - dismissal_users = ["a"] - dismissal_teams = ["b"] - dismissal_apps = ["c"] - bypass_pull_request_allowances { - users = ["d"] - teams = [github_team.test.slug] - apps = ["e"] - } - } - - depends_on = [github_team_repository.test] + repository = github_repository.test.name + branch = "main" + + required_pull_request_reviews { + dismiss_stale_reviews = true + require_code_owner_reviews = true + required_approving_review_count = 1 + require_last_push_approval = true + dismissal_users = ["a"] + dismissal_teams = ["b"] + dismissal_apps = ["c"] + bypass_pull_request_allowances { + users = ["d"] + teams = [github_team.test.slug] + apps = ["e"] + } + } + + depends_on = [github_team_repository.test] } - `, randomID) + `, testRepoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -583,15 +592,16 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures required pull request reviews with bypass allowances", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testResourceName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" } resource "github_team_repository" "test" { @@ -601,19 +611,19 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { } resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" + repository = github_repository.test.name + branch = "main" - required_pull_request_reviews { + required_pull_request_reviews { bypass_pull_request_allowances { teams = [github_team.test.slug] } - } + } depends_on = [github_team_repository.test] } - `, randomID) + `, testResourceName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( @@ -638,14 +648,15 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { t.Run("configures branch push restrictions", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testResourceName := fmt.Sprintf("%sbranch-protection-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" - auto_init = true + name = "%s" + auto_init = true } resource "github_team" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" } resource "github_team_repository" "test" { @@ -656,15 +667,15 @@ func TestAccGithubBranchProtectionV3(t *testing.T) { resource "github_branch_protection_v3" "test" { - repository = github_repository.test.name - branch = "main" + repository = github_repository.test.name + branch = "main" - restrictions { + restrictions { teams = ["${github_team.test.slug}"] - } + } } - `, randomID) + `, testResourceName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_branch_test.go b/github/resource_github_branch_test.go index 9a2cbe89fa..ae13c32355 100644 --- a/github/resource_github_branch_test.go +++ b/github/resource_github_branch_test.go @@ -11,9 +11,10 @@ import ( func TestAccGithubBranch(t *testing.T) { t.Run("creates a branch directly", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -21,7 +22,7 @@ func TestAccGithubBranch(t *testing.T) { repository = github_repository.test.name branch = "test" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -41,9 +42,10 @@ func TestAccGithubBranch(t *testing.T) { t.Run("creates a branch named main directly and a repository with a gitignore template", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true gitignore_template = "Python" } @@ -52,7 +54,7 @@ func TestAccGithubBranch(t *testing.T) { repository = github_repository.test.id branch = "main" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -80,9 +82,10 @@ func TestAccGithubBranch(t *testing.T) { t.Run("creates a branch from a source branch", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -96,7 +99,7 @@ func TestAccGithubBranch(t *testing.T) { source_branch = github_branch.source.branch branch = "test" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -116,9 +119,10 @@ func TestAccGithubBranch(t *testing.T) { t.Run("renames a branch without replacement", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-branch-%s", testResourcePrefix, randomID) initialConfig := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -126,11 +130,11 @@ func TestAccGithubBranch(t *testing.T) { repository = github_repository.test.id branch = "initial" } - `, randomID) + `, repoName) renamedConfig := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%[1]s" auto_init = true } @@ -138,7 +142,7 @@ func TestAccGithubBranch(t *testing.T) { repository = github_repository.test.id branch = "renamed" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_codespaces_organization_secret_repositories_test.go b/github/resource_github_codespaces_organization_secret_repositories_test.go index 653d58e820..07d3ee9cb9 100644 --- a/github/resource_github_codespaces_organization_secret_repositories_test.go +++ b/github/resource_github_codespaces_organization_secret_repositories_test.go @@ -11,6 +11,9 @@ import ( func TestAccGithubCodespacesOrganizationSecretRepositories(t *testing.T) { t.Run("set repository allowlist for an organization secret", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName1 := fmt.Sprintf("%srepo-cs-org-secret-1-%s", testResourcePrefix, randomID) + repoName2 := fmt.Sprintf("%srepo-cs-org-secret-2-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_actions_organization_secret" "test" { secret_name = "TEST" @@ -19,12 +22,12 @@ func TestAccGithubCodespacesOrganizationSecretRepositories(t *testing.T) { } resource "github_repository" "test_repo_1" { - name = "tf-acc-test-%s-1" + name = "%s" visibility = "private" } resource "github_repository" "test_repo_2" { - name = "tf-acc-test-%s-2" + name = "%s" visibility = "private" } @@ -35,7 +38,7 @@ func TestAccGithubCodespacesOrganizationSecretRepositories(t *testing.T) { github_repository.test_repo_2.repo_id ] } - `, randomID, randomID) + `, repoName1, repoName2) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasPaidOrgs(t) }, diff --git a/github/resource_github_codespaces_secret_test.go b/github/resource_github_codespaces_secret_test.go index 54ae4c2c29..55bf8e9665 100644 --- a/github/resource_github_codespaces_secret_test.go +++ b/github/resource_github_codespaces_secret_test.go @@ -14,17 +14,18 @@ import ( func TestAccGithubCodespacesSecret(t *testing.T) { t.Run("reads a repository public key without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-codespaces-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_codespaces_public_key" "test_pk" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet( @@ -49,12 +50,13 @@ func TestAccGithubCodespacesSecret(t *testing.T) { t.Run("creates and updates secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-codespaces-%s", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) updatedSecretValue := base64.StdEncoding.EncodeToString([]byte("updated_super_secret_value")) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_codespaces_secret" "plaintext_secret" { @@ -68,7 +70,7 @@ func TestAccGithubCodespacesSecret(t *testing.T) { secret_name = "test_encrypted_secret" encrypted_value = "%s" } - `, randomID, secretValue, secretValue) + `, repoName, secretValue, secretValue) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -125,8 +127,8 @@ func TestAccGithubCodespacesSecret(t *testing.T) { t.Run("creates and updates repository name without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) - updatedRepoName := fmt.Sprintf("tf-acc-test-%s-updated", randomID) + repoName := fmt.Sprintf("%srepo-codespaces-%s", testResourcePrefix, randomID) + updatedRepoName := fmt.Sprintf("%s-updated", repoName) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) config := fmt.Sprintf(` @@ -208,9 +210,10 @@ func TestAccGithubCodespacesSecret(t *testing.T) { t.Run("deletes secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-codespaces-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_codespaces_secret" "plaintext_secret" { @@ -222,7 +225,7 @@ func TestAccGithubCodespacesSecret(t *testing.T) { repository = github_repository.test.name secret_name = "test_encrypted_secret" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_dependabot_organization_secret_repositories_test.go b/github/resource_github_dependabot_organization_secret_repositories_test.go index bd62f0fa80..4ff6354b42 100644 --- a/github/resource_github_dependabot_organization_secret_repositories_test.go +++ b/github/resource_github_dependabot_organization_secret_repositories_test.go @@ -11,6 +11,9 @@ import ( func TestAccGithubDependabotOrganizationSecretRepositories(t *testing.T) { t.Run("set repository allowlist for an organization secret", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName1 := fmt.Sprintf("%srepo-depbot-org-secret-1-%s", testResourcePrefix, randomID) + repoName2 := fmt.Sprintf("%srepo-depbot-org-secret-2-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_actions_organization_secret" "test" { secret_name = "TEST" @@ -19,13 +22,13 @@ func TestAccGithubDependabotOrganizationSecretRepositories(t *testing.T) { } resource "github_repository" "test_repo_1" { - name = "tf-acc-test-%s-1" + name = "%s" visibility = "private" vulnerability_alerts = "true" } resource "github_repository" "test_repo_2" { - name = "tf-acc-test-%s-2" + name = "%s" visibility = "private" vulnerability_alerts = "true" } @@ -37,7 +40,7 @@ func TestAccGithubDependabotOrganizationSecretRepositories(t *testing.T) { github_repository.test_repo_2.repo_id ] } - `, randomID, randomID) + `, repoName1, repoName2) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasPaidOrgs(t) }, diff --git a/github/resource_github_dependabot_secret_test.go b/github/resource_github_dependabot_secret_test.go index fe5b69c921..62787c8d35 100644 --- a/github/resource_github_dependabot_secret_test.go +++ b/github/resource_github_dependabot_secret_test.go @@ -14,17 +14,18 @@ import ( func TestAccGithubDependabotSecret(t *testing.T) { t.Run("reads a repository public key without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-dependabot-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } data "github_dependabot_public_key" "test_pk" { repository = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet( @@ -49,12 +50,13 @@ func TestAccGithubDependabotSecret(t *testing.T) { t.Run("creates and updates secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-dependabot-%s", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) updatedSecretValue := base64.StdEncoding.EncodeToString([]byte("updated_super_secret_value")) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_dependabot_secret" "plaintext_secret" { @@ -68,7 +70,7 @@ func TestAccGithubDependabotSecret(t *testing.T) { secret_name = "test_encrypted_secret" encrypted_value = "%s" } - `, randomID, secretValue, secretValue) + `, repoName, secretValue, secretValue) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -125,8 +127,8 @@ func TestAccGithubDependabotSecret(t *testing.T) { t.Run("creates and updates repository name without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) - updatedRepoName := fmt.Sprintf("tf-acc-test-%s-updated", randomID) + repoName := fmt.Sprintf("%srepo-dependabot-%s", testResourcePrefix, randomID) + updatedRepoName := fmt.Sprintf("%srepo-dependabot-%s-upd", testResourcePrefix, randomID) secretValue := base64.StdEncoding.EncodeToString([]byte("super_secret_value")) config := fmt.Sprintf(` @@ -210,9 +212,10 @@ func TestAccGithubDependabotSecret(t *testing.T) { t.Run("deletes secrets without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-dependabot-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_dependabot_secret" "plaintext_secret" { @@ -224,7 +227,7 @@ func TestAccGithubDependabotSecret(t *testing.T) { repository = github_repository.test.name secret_name = "test_encrypted_secret" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_enterprise_organization_test.go b/github/resource_github_enterprise_organization_test.go index 68497cdd13..e9616bee77 100644 --- a/github/resource_github_enterprise_organization_test.go +++ b/github/resource_github_enterprise_organization_test.go @@ -13,29 +13,29 @@ import ( func TestAccGithubEnterpriseOrganization(t *testing.T) { t.Run("creates and updates an enterprise organization without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - orgName := fmt.Sprintf("tf-acc-test-%s", randomID) + orgName := fmt.Sprintf("%s%s", testResourcePrefix, randomID) desc := "Initial org description" updatedDesc := "Updated org description" config := fmt.Sprintf(` - data "github_enterprise" "enterprise" { + data "github_enterprise" "enterprise" { slug = "%s" - } + } - data "github_user" "current" { + data "github_user" "current" { username = "" - } + } - resource "github_enterprise_organization" "org" { + resource "github_enterprise_organization" "org" { enterprise_id = data.github_enterprise.enterprise.id name = "%s" description = "%s" billing_email = data.github_user.current.email admin_logins = [ - data.github_user.current.login + data.github_user.current.login ] - } + } `, testAccConf.enterpriseSlug, orgName, desc) checks := map[string]resource.TestCheckFunc{ @@ -87,25 +87,25 @@ func TestAccGithubEnterpriseOrganization(t *testing.T) { t.Run("deletes an enterprise organization without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - orgName := fmt.Sprintf("tf-acc-test-%s", randomID) + orgName := fmt.Sprintf("%s%s", testResourcePrefix, randomID) config := fmt.Sprintf(` - data "github_enterprise" "enterprise" { - slug = "%s" - } + data "github_enterprise" "enterprise" { + slug = "%s" + } - data "github_user" "current" { - username = "" - } + data "github_user" "current" { + username = "" + } - resource "github_enterprise_organization" "org" { - enterprise_id = data.github_enterprise.enterprise.id - name = "%s" - billing_email = data.github_user.current.email - admin_logins = [ - data.github_user.current.login - ] - } + resource "github_enterprise_organization" "org" { + enterprise_id = data.github_enterprise.enterprise.id + name = "%s" + billing_email = data.github_user.current.email + admin_logins = [ + data.github_user.current.login + ] + } `, testAccConf.enterpriseSlug, orgName) resource.Test(t, resource.TestCase{ @@ -131,24 +131,24 @@ func TestAccGithubEnterpriseOrganization(t *testing.T) { updatedDesc := "Updated org description" config := fmt.Sprintf(` - data "github_enterprise" "enterprise" { + data "github_enterprise" "enterprise" { slug = "%s" - } + } - data "github_user" "current" { + data "github_user" "current" { username = "" - } + } - resource "github_enterprise_organization" "org" { + resource "github_enterprise_organization" "org" { enterprise_id = data.github_enterprise.enterprise.id name = "%s" display_name = "%s" description = "%s" billing_email = data.github_user.current.email admin_logins = [ - data.github_user.current.login + data.github_user.current.login ] - } + } `, testAccConf.enterpriseSlug, orgName, displayName, desc) checks := map[string]resource.TestCheckFunc{ @@ -220,45 +220,45 @@ func TestAccGithubEnterpriseOrganization(t *testing.T) { updatedDesc := "Updated org description" configWithoutDisplayName := fmt.Sprintf(` - data "github_enterprise" "enterprise" { + data "github_enterprise" "enterprise" { slug = "%s" - } + } - data "github_user" "current" { + data "github_user" "current" { username = "" - } + } - resource "github_enterprise_organization" "org" { + resource "github_enterprise_organization" "org" { enterprise_id = data.github_enterprise.enterprise.id name = "%s" description = "%s" billing_email = data.github_user.current.email admin_logins = [ - data.github_user.current.login + data.github_user.current.login ] - } + } `, testAccConf.enterpriseSlug, orgName, desc) configWithDisplayName := fmt.Sprintf(` data "github_enterprise" "enterprise" { - slug = "%s" + slug = "%s" } data "github_user" "current" { - username = "" + username = "" } resource "github_enterprise_organization" "org" { - enterprise_id = data.github_enterprise.enterprise.id - name = "%s" - display_name = "%s" - description = "%s" - billing_email = data.github_user.current.email - admin_logins = [ + enterprise_id = data.github_enterprise.enterprise.id + name = "%s" + display_name = "%s" + description = "%s" + billing_email = data.github_user.current.email + admin_logins = [ data.github_user.current.login - ] + ] } - `, testAccConf.enterpriseSlug, orgName, displayName, desc) + `, testAccConf.enterpriseSlug, orgName, displayName, desc) checks := map[string]resource.TestCheckFunc{ "create": resource.ComposeTestCheckFunc( @@ -360,22 +360,22 @@ func TestAccGithubEnterpriseOrganization(t *testing.T) { config := fmt.Sprintf(` data "github_enterprise" "enterprise" { - slug = "%s" + slug = "%s" } data "github_user" "current" { - username = "" + username = "" } resource "github_enterprise_organization" "org" { - enterprise_id = data.github_enterprise.enterprise.id - name = "%s" - billing_email = data.github_user.current.email - admin_logins = [ + enterprise_id = data.github_enterprise.enterprise.id + name = "%s" + billing_email = data.github_user.current.email + admin_logins = [ data.github_user.current.login - ] + ] } - `, testAccConf.enterpriseSlug, orgName) + `, testAccConf.enterpriseSlug, orgName) check := resource.ComposeTestCheckFunc() @@ -403,23 +403,23 @@ func TestAccGithubEnterpriseOrganization(t *testing.T) { config := fmt.Sprintf(` data "github_enterprise" "enterprise" { - slug = "%s" + slug = "%s" } data "github_user" "current" { - username = "" + username = "" } resource "github_enterprise_organization" "org" { - enterprise_id = data.github_enterprise.enterprise.id - name = "%s" - description = "org description" - billing_email = data.github_user.current.email - admin_logins = [ + enterprise_id = data.github_enterprise.enterprise.id + name = "%s" + description = "org description" + billing_email = data.github_user.current.email + admin_logins = [ data.github_user.current.login - ] + ] } - `, testAccConf.enterpriseSlug, orgName) + `, testAccConf.enterpriseSlug, orgName) check := resource.ComposeTestCheckFunc() @@ -447,23 +447,23 @@ func TestAccGithubEnterpriseOrganization(t *testing.T) { config := fmt.Sprintf(` data "github_enterprise" "enterprise" { - slug = "%s" + slug = "%s" } data "github_user" "current" { - username = "" + username = "" } resource "github_enterprise_organization" "org" { - enterprise_id = data.github_enterprise.enterprise.id - name = "%s" - description = "org description" - billing_email = data.github_user.current.email - admin_logins = [ + enterprise_id = data.github_enterprise.enterprise.id + name = "%s" + description = "org description" + billing_email = data.github_user.current.email + admin_logins = [ data.github_user.current.login - ] + ] } - `, testAccConf.enterpriseSlug, orgName) + `, testAccConf.enterpriseSlug, orgName) check := resource.ComposeTestCheckFunc() diff --git a/github/resource_github_etag_acc_test.go b/github/resource_github_etag_acc_test.go index ee8f634610..784885bf48 100644 --- a/github/resource_github_etag_acc_test.go +++ b/github/resource_github_etag_acc_test.go @@ -11,7 +11,7 @@ import ( // TestAccGithubRepositoryEtagPresent tests that etag field is populated. func TestAccGithubRepositoryEtagPresent(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-etag-%s", randomID) + repoName := fmt.Sprintf("%srepo-etag-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -38,7 +38,7 @@ func TestAccGithubRepositoryEtagPresent(t *testing.T) { // TestAccGithubRepositoryEtagNoDiff tests that re-running the same config shows no changes. func TestAccGithubRepositoryEtagNoDiff(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-etag-nodiff-%s", randomID) + repoName := fmt.Sprintf("%srepo-etag-nodiff-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { diff --git a/github/resource_github_issue_label_test.go b/github/resource_github_issue_label_test.go index 72c50e10c9..b56bfbfe54 100644 --- a/github/resource_github_issue_label_test.go +++ b/github/resource_github_issue_label_test.go @@ -12,13 +12,14 @@ import ( func TestAccGithubIssueLabel(t *testing.T) { t.Run("creates and updates labels without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-issue-label-%s", testResourcePrefix, randomID) description := "label_description" updatedDescription := "updated_label_description" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -28,7 +29,7 @@ func TestAccGithubIssueLabel(t *testing.T) { color = "000000" description = "%s" } - `, randomID, description) + `, repoName, description) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -65,10 +66,11 @@ func TestAccGithubIssueLabel(t *testing.T) { t.Run("can delete labels from archived repositories without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-issue-label-arch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-archive-%s" + name = "%s" auto_init = true } @@ -78,7 +80,7 @@ func TestAccGithubIssueLabel(t *testing.T) { color = "ff0000" description = "Test label for archived repo" } - `, randomID) + `, repoName) archivedConfig := strings.Replace(config, `auto_init = true`, @@ -112,11 +114,11 @@ func TestAccGithubIssueLabel(t *testing.T) { { Config: fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-archive-%s" + name = "%s" auto_init = true archived = true } - `, randomID), + `, repoName), }, }, }) diff --git a/github/resource_github_issue_labels_test.go b/github/resource_github_issue_labels_test.go index 6b0f6756ab..d512288081 100644 --- a/github/resource_github_issue_labels_test.go +++ b/github/resource_github_issue_labels_test.go @@ -11,7 +11,7 @@ import ( func TestAccGithubIssueLabels(t *testing.T) { t.Run("authoritatively overtakes existing labels", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + repoName := fmt.Sprintf("%srepo-issue-labels-%s", testResourcePrefix, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) empty := []map[string]any{} resource.Test(t, resource.TestCase{ @@ -117,7 +117,7 @@ func TestAccGithubIssueLabelsArchived(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) t.Run("can delete labels from archived repositories without error", func(t *testing.T) { - repoName := fmt.Sprintf("tf-acc-test-labels-archive-%s", randomID) + repoName := fmt.Sprintf("%srepo-labels-arch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { diff --git a/github/resource_github_issue_test.go b/github/resource_github_issue_test.go index db084a21de..3741dd15a6 100644 --- a/github/resource_github_issue_test.go +++ b/github/resource_github_issue_test.go @@ -13,6 +13,7 @@ import ( func TestAccGithubIssue(t *testing.T) { t.Run("creates an issue without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-issue-%s", testResourcePrefix, randomID) title := "issue_title" body := "issue_body" labels := "\"bug\", \"enhancement\"" @@ -22,7 +23,7 @@ func TestAccGithubIssue(t *testing.T) { issueHCL := ` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true has_issues = true } @@ -45,7 +46,7 @@ func TestAccGithubIssue(t *testing.T) { milestone_number = github_repository_milestone.test.number } ` - config := fmt.Sprintf(issueHCL, randomID, title, body, labels, testAccConf.username) + config := fmt.Sprintf(issueHCL, repoName, title, body, labels, testAccConf.username) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -101,7 +102,7 @@ func TestAccGithubIssue(t *testing.T) { Check: checks["before"], }, { - Config: fmt.Sprintf(issueHCL, randomID, updatedTitle, updatedBody, updatedLabels, testAccConf.owner), + Config: fmt.Sprintf(issueHCL, repoName, updatedTitle, updatedBody, updatedLabels, testAccConf.owner), Check: checks["after"], }, }, @@ -110,9 +111,10 @@ func TestAccGithubIssue(t *testing.T) { t.Run("imports a issue without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-issue-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" has_issues = true } @@ -120,11 +122,11 @@ func TestAccGithubIssue(t *testing.T) { repository = github_repository.test.name title = github_repository.test.name } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_issue.test", "title"), - resource.TestCheckResourceAttr("github_issue.test", "title", fmt.Sprintf(`tf-acc-test-%s`, randomID)), + resource.TestCheckResourceAttr("github_issue.test", "title", repoName), ) resource.Test(t, resource.TestCase{ diff --git a/github/resource_github_organization_role_team_assignment_test.go b/github/resource_github_organization_role_team_assignment_test.go index e56f270344..43d423dfbb 100644 --- a/github/resource_github_organization_role_team_assignment_test.go +++ b/github/resource_github_organization_role_team_assignment_test.go @@ -19,7 +19,7 @@ func TestAccGithubOrganizationRoleTeamAssignment(t *testing.T) { t.Run("creates repo assignment without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamSlug := fmt.Sprintf("tf-acc-test-team-repo-%s", randomID) + teamSlug := fmt.Sprintf("%steam-role-assign-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { @@ -59,7 +59,7 @@ func TestAccGithubOrganizationRoleTeamAssignment(t *testing.T) { // More tests can go here following the same format... t.Run("create and re-creates role assignment without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamSlug := fmt.Sprintf("tf-acc-test-team-repo-%s", randomID) + teamSlug := fmt.Sprintf("%steam-role-assign-%s", testResourcePrefix, randomID) configs := map[string]string{ "before": fmt.Sprintf(` diff --git a/github/resource_github_organization_role_team_test.go b/github/resource_github_organization_role_team_test.go index 3df806863e..e38f7ab414 100644 --- a/github/resource_github_organization_role_team_test.go +++ b/github/resource_github_organization_role_team_test.go @@ -12,7 +12,7 @@ import ( func TestAccGithubOrganizationRoleTeam(t *testing.T) { t.Run("adds team to an organization org role", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName := fmt.Sprintf("tf-acc-team-%s", randomID) + teamName := fmt.Sprintf("%steam-org-role-%s", testResourcePrefix, randomID) roleId := 8134 config := fmt.Sprintf(` resource "github_team" "test" { diff --git a/github/resource_github_organization_role_user_test.go b/github/resource_github_organization_role_user_test.go index 78bde9e5be..6a12c2bac7 100644 --- a/github/resource_github_organization_role_user_test.go +++ b/github/resource_github_organization_role_user_test.go @@ -2,7 +2,6 @@ package github import ( "fmt" - "os" "strconv" "testing" @@ -11,18 +10,13 @@ import ( func TestAccGithubOrganizationRoleUser(t *testing.T) { t.Run("adds user to an organization org role", func(t *testing.T) { - login := os.Getenv("GITHUB_IN_ORG_USER") - if len(login) == 0 { - t.Skip("set inOrgUser to unskip this test run") - } - roleId := 8134 config := fmt.Sprintf(` resource "github_organization_role_user" "test" { role_id = %d login = "%s" } - `, roleId, login) + `, roleId, testAccConf.testOrgUser) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -32,7 +26,7 @@ func TestAccGithubOrganizationRoleUser(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("github_organization_role_user.test", "role_id", strconv.Itoa(roleId)), - resource.TestCheckResourceAttr("github_organization_role_user.test", "login", login), + resource.TestCheckResourceAttr("github_organization_role_user.test", "login", testAccConf.testOrgUser), ), }, }, diff --git a/github/resource_github_organization_security_manager_test.go b/github/resource_github_organization_security_manager_test.go index 4f3dc94907..e8611c133b 100644 --- a/github/resource_github_organization_security_manager_test.go +++ b/github/resource_github_organization_security_manager_test.go @@ -11,15 +11,16 @@ import ( func TestAccGithubOrganizationSecurityManager(t *testing.T) { t.Run("adds team as security manager", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-sec-mgr-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-%s" + name = "%s" } resource "github_organization_security_manager" "test" { team_slug = github_team.test.slug } - `, randomID) + `, teamName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -30,7 +31,7 @@ func TestAccGithubOrganizationSecurityManager(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair("github_team.test", "ID", "github_organization_security_manager.test", "ID"), resource.TestCheckResourceAttrPair("github_team.test", "slug", "github_organization_security_manager.test", "team_slug"), - resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", fmt.Sprintf("tf-acc-%s", randomID)), + resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", teamName), ), }, }, @@ -39,25 +40,27 @@ func TestAccGithubOrganizationSecurityManager(t *testing.T) { t.Run("handles team name changes", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-sec-mgr-%s", testResourcePrefix, randomID) + teamNameUpdated := fmt.Sprintf("%s-updated", teamName) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-%s" + name = "%s" } resource "github_organization_security_manager" "test" { team_slug = github_team.test.slug } - `, randomID) + `, teamName) configUpdated := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-updated-%s" + name = "%s" } resource "github_organization_security_manager" "test" { team_slug = github_team.test.slug } - `, randomID) + `, teamNameUpdated) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -68,7 +71,7 @@ func TestAccGithubOrganizationSecurityManager(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair("github_team.test", "ID", "github_organization_security_manager.test", "ID"), resource.TestCheckResourceAttrPair("github_team.test", "slug", "github_organization_security_manager.test", "team_slug"), - resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", fmt.Sprintf("tf-acc-%s", randomID)), + resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", teamName), ), }, { @@ -76,53 +79,7 @@ func TestAccGithubOrganizationSecurityManager(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair("github_team.test", "ID", "github_organization_security_manager.test", "ID"), resource.TestCheckResourceAttrPair("github_team.test", "slug", "github_organization_security_manager.test", "team_slug"), - resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", fmt.Sprintf("tf-acc-updated-%s", randomID)), - ), - }, - }, - }) - }) - - t.Run("handles team name changes", func(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - config := fmt.Sprintf(` - resource "github_team" "test" { - name = "tf-acc-%s" - } - - resource "github_organization_security_manager" "test" { - team_slug = github_team.test.slug - } - `, randomID) - - configUpdated := fmt.Sprintf(` - resource "github_team" "test" { - name = "tf-acc-updated-%s" - } - - resource "github_organization_security_manager" "test" { - team_slug = github_team.test.slug - } - `, randomID) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { skipUnlessHasOrgs(t) }, - ProviderFactories: providerFactories, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair("github_team.test", "ID", "github_organization_security_manager.test", "ID"), - resource.TestCheckResourceAttrPair("github_team.test", "slug", "github_organization_security_manager.test", "team_slug"), - resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", fmt.Sprintf("tf-acc-%s", randomID)), - ), - }, - { - Config: configUpdated, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair("github_team.test", "ID", "github_organization_security_manager.test", "ID"), - resource.TestCheckResourceAttrPair("github_team.test", "slug", "github_organization_security_manager.test", "team_slug"), - resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", fmt.Sprintf("tf-acc-updated-%s", randomID)), + resource.TestCheckResourceAttr("github_organization_security_manager.test", "team_slug", teamNameUpdated), ), }, }, diff --git a/github/resource_github_organization_webhook_test.go b/github/resource_github_organization_webhook_test.go index 7cf063bb33..77c44b9a09 100644 --- a/github/resource_github_organization_webhook_test.go +++ b/github/resource_github_organization_webhook_test.go @@ -12,10 +12,11 @@ import ( func TestAccGithubOrganizationWebhook(t *testing.T) { t.Run("creates and updates webhooks without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-org-webhook-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -29,7 +30,7 @@ func TestAccGithubOrganizationWebhook(t *testing.T) { events = ["pull_request"] } - `, randomID) + `, repoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -66,10 +67,11 @@ func TestAccGithubOrganizationWebhook(t *testing.T) { t.Run("imports webhooks without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-org-webhook-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -83,7 +85,7 @@ func TestAccGithubOrganizationWebhook(t *testing.T) { events = ["issues"] } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_project_card_test.go b/github/resource_github_project_card_test.go index 699def81c7..bd802b5b55 100644 --- a/github/resource_github_project_card_test.go +++ b/github/resource_github_project_card_test.go @@ -15,10 +15,11 @@ func TestAccGithubProjectCard(t *testing.T) { t.Run("creates a project card using a note", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testResourceName := fmt.Sprintf("%sproject-card-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_organization_project" "project" { - name = "tf-acc-%s" + name = "%s" body = "This is an organization project." } @@ -32,7 +33,7 @@ func TestAccGithubProjectCard(t *testing.T) { note = "## Unaccepted 👇" } - `, randomID) + `, testResourceName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet( @@ -54,10 +55,11 @@ func TestAccGithubProjectCard(t *testing.T) { t.Run("creates a project card using an issue", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-project-card-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" has_projects = true has_issues = true } @@ -86,7 +88,7 @@ func TestAccGithubProjectCard(t *testing.T) { content_type = "Issue" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( func(state *terraform.State) error { diff --git a/github/resource_github_release_test.go b/github/resource_github_release_test.go index b9f28a8195..4b2694272b 100644 --- a/github/resource_github_release_test.go +++ b/github/resource_github_release_test.go @@ -14,11 +14,12 @@ import ( func TestAccGithubReleaseResource(t *testing.T) { t.Run("create a release with defaults", func(t *testing.T) { randomRepoPart := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-release-%s", testResourcePrefix, randomRepoPart) randomVersion := fmt.Sprintf("v1.0.%d", acctest.RandIntRange(0, 9999)) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -26,7 +27,7 @@ func TestAccGithubReleaseResource(t *testing.T) { repository = github_repository.test.name tag_name = "%s" } - `, randomRepoPart, randomVersion) + `, repoName, randomVersion) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -76,12 +77,13 @@ func TestAccGithubReleaseResource(t *testing.T) { t.Run("create a release on branch", func(t *testing.T) { randomRepoPart := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-release-%s", testResourcePrefix, randomRepoPart) randomVersion := fmt.Sprintf("v1.0.%d", acctest.RandIntRange(0, 9999)) testBranchName := "test" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -98,7 +100,7 @@ func TestAccGithubReleaseResource(t *testing.T) { draft = false prerelease = false } - `, randomRepoPart, testBranchName, randomVersion) + `, repoName, testBranchName, randomVersion) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_repository_autolink_reference_test.go b/github/resource_github_repository_autolink_reference_test.go index 7151cf8be6..d057808cf9 100644 --- a/github/resource_github_repository_autolink_reference_test.go +++ b/github/resource_github_repository_autolink_reference_test.go @@ -12,9 +12,10 @@ import ( func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("creates repository autolink reference without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-autolink-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%s" + name = "%s" description = "Test autolink creation" } @@ -47,7 +48,7 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { key_prefix = "TEST4-" target_url_template = "https://example.com:8443/TEST-" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( // autolink_default @@ -106,9 +107,10 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("imports repository autolink reference without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-autolink-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%s" + name = "%s" description = "Test autolink creation" } @@ -141,7 +143,7 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { key_prefix = "TEST4-" target_url_template = "https://example.com:8443/TEST-" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( // autolink_default @@ -199,28 +201,28 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { ResourceName: "github_repository_autolink_reference.autolink_default", ImportState: true, ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), + ImportStateIdPrefix: fmt.Sprintf("%s/", repoName), }, // autolink_alphanumeric { ResourceName: "github_repository_autolink_reference.autolink_alphanumeric", ImportState: true, ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), + ImportStateIdPrefix: fmt.Sprintf("%s/", repoName), }, // autolink_numeric { ResourceName: "github_repository_autolink_reference.autolink_numeric", ImportState: true, ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), + ImportStateIdPrefix: fmt.Sprintf("%s/", repoName), }, // autolink_with_port { ResourceName: "github_repository_autolink_reference.autolink_with_port", ImportState: true, ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), + ImportStateIdPrefix: fmt.Sprintf("%s/", repoName), }, }, }) @@ -228,9 +230,10 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("imports repository autolink reference by key prefix without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-autolink-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "oof" { - name = "oof-%s" + name = "%s" description = "Test autolink creation" } @@ -240,7 +243,7 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { key_prefix = "OOF-" target_url_template = "https://awesome.com/find/OOF-" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -253,12 +256,12 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { ResourceName: "github_repository_autolink_reference.autolink", ImportState: true, ImportStateVerify: true, - ImportStateId: fmt.Sprintf("oof-%s/OOF-", randomID), + ImportStateId: fmt.Sprintf("%s/OOF-", repoName), }, { ResourceName: "github_repository_autolink_reference.autolink", ImportState: true, - ImportStateId: fmt.Sprintf("oof-%s/OCTOCAT-", randomID), + ImportStateId: fmt.Sprintf("%s/OCTOCAT-", repoName), ExpectError: regexp.MustCompile(`cannot find autolink reference`), }, }, @@ -267,9 +270,10 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { t.Run("deletes repository autolink reference without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-autolink-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%s" + name = "%s" description = "Test autolink creation" } @@ -279,7 +283,7 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) { key_prefix = "TEST1-" target_url_template = "https://example.com/TEST-" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_repository_collaborator_test.go b/github/resource_github_repository_collaborator_test.go index d162db1c8f..62c7466d69 100644 --- a/github/resource_github_repository_collaborator_test.go +++ b/github/resource_github_repository_collaborator_test.go @@ -2,6 +2,7 @@ package github import ( "fmt" + "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -15,9 +16,10 @@ func TestAccGithubRepositoryCollaborator(t *testing.T) { t.Run("creates invitations without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-collab-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -26,7 +28,7 @@ func TestAccGithubRepositoryCollaborator(t *testing.T) { username = "%s" permission = "triage" } - `, randomID, testAccConf.testExternalUser) + `, repoName, testAccConf.testExternalUser) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -49,9 +51,10 @@ func TestAccGithubRepositoryCollaborator(t *testing.T) { t.Run("creates invitations when repository contains the org name", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-collab-%s", testResourcePrefix, randomID) configWithOwner := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -60,7 +63,7 @@ func TestAccGithubRepositoryCollaborator(t *testing.T) { username = "%s" permission = "triage" } - `, randomID, testAccConf.owner, testAccConf.testExternalUser) + `, repoName, testAccConf.owner, testAccConf.testExternalUser) checkWithOwner := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -118,16 +121,18 @@ func TestParseRepoName(t *testing.T) { } func TestAccGithubRepositoryCollaboratorArchivedRepo(t *testing.T) { - if len(testAccConf.testExternalUser) == 0 { - t.Skip("No external user provided") + // Note: This test requires GH_TEST_COLLABORATOR to be set to a valid GitHub username and it won't work with `testExternalUser` + testCollaborator := os.Getenv("GH_TEST_COLLABORATOR") + if testCollaborator == "" { + t.Skip("GH_TEST_COLLABORATOR not set, skipping archived repository collaborator test") } - - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("can delete collaborators from archived repositories without error", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-collab-arch-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-collab-archive-%s" + name = "%s" auto_init = true } @@ -136,11 +141,11 @@ func TestAccGithubRepositoryCollaboratorArchivedRepo(t *testing.T) { username = "%s" permission = "pull" } - `, randomID, testAccConf.testExternalUser) + `, repoName, testCollaborator) archivedConfig := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-collab-archive-%s" + name = "%s" auto_init = true archived = true } @@ -150,7 +155,7 @@ func TestAccGithubRepositoryCollaboratorArchivedRepo(t *testing.T) { username = "%s" permission = "pull" } - `, randomID, testAccConf.testExternalUser) + `, repoName, testCollaborator) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -183,11 +188,11 @@ func TestAccGithubRepositoryCollaboratorArchivedRepo(t *testing.T) { { Config: fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-collab-archive-%s" + name = "%s" auto_init = true archived = true } - `, randomID), + `, repoName), }, }, }) diff --git a/github/resource_github_repository_collaborators_test.go b/github/resource_github_repository_collaborators_test.go index de71ceef6b..3e792ac979 100644 --- a/github/resource_github_repository_collaborators_test.go +++ b/github/resource_github_repository_collaborators_test.go @@ -25,7 +25,7 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { t.Run("adds user collaborator", func(t *testing.T) { conn := meta.v3client randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) + repoName := fmt.Sprintf("%srepo-collabs-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -94,8 +94,9 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { ctx := t.Context() conn := meta.v3client randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) - teamName := fmt.Sprintf("tf-acc-test-team-%s", randomID) + repoName := fmt.Sprintf("%srepo-collabs-%s", testResourcePrefix, randomID) + teamName := fmt.Sprintf("%steam-collabs-%s", testResourcePrefix, randomID) + collaboratorUser := testAccConf.testOrgUser config := fmt.Sprintf(` resource "github_repository" "test" { @@ -121,7 +122,7 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { permission = "pull" } } - `, repoName, teamName, testAccConf.testExternalUser) + `, repoName, teamName, collaboratorUser) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -140,8 +141,8 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { teamAttrs := state.RootModule().Resources["github_team.test"].Primary.Attributes collaborators := state.RootModule().Resources["github_repository_collaborators.test_repo_collaborators"].Primary for name, val := range collaborators.Attributes { - if strings.HasPrefix(name, "user.") && strings.HasSuffix(name, ".username") && val != testAccConf.testExternalUser { - return fmt.Errorf("expected user.*.username to be set to %s, was %s", testAccConf.testExternalUser, val) + if strings.HasPrefix(name, "user.") && strings.HasSuffix(name, ".username") && val != collaboratorUser { + return fmt.Errorf("expected user.*.username to be set to %s, was %s", collaboratorUser, val) } if strings.HasPrefix(name, "user.") && strings.HasSuffix(name, ".permission") && val != "admin" { return fmt.Errorf("expected user.*.permission to be set to admin, was %s", val) @@ -158,11 +159,11 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { return err } if len(users) != 1 { - return fmt.Errorf("expected %s to be a collaborator for repo %s/%s", testAccConf.testExternalUser, owner, repoName) + return fmt.Errorf("expected 1 collaborator (%s) for repo %s/%s , found %d", collaboratorUser, owner, repoName, len(users)) } perm := getPermission(users[0].GetRoleName()) if perm != "admin" { - return fmt.Errorf("expected %s to have admin perms for repo %s/%s, found %s", testAccConf.testExternalUser, owner, repoName, perm) + return fmt.Errorf("expected %s to have admin perms for repo %s/%s, found %s", collaboratorUser, owner, repoName, perm) } teams, _, err := conn.Repositories.ListTeams(ctx, owner, repoName, nil) if err != nil { @@ -191,7 +192,7 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { ctx := t.Context() conn := meta.v3client randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) + repoName := fmt.Sprintf("%srepo-collabs-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -284,9 +285,9 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { ctx := t.Context() conn := meta.v3client randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) - teamName1 := fmt.Sprintf("tf-acc-test-team-1-%s", randomID) - teamName2 := fmt.Sprintf("tf-acc-test-team-2-%s", randomID) + repoName := fmt.Sprintf("%srepo-collabs-%s", testResourcePrefix, randomID) + teamName1 := fmt.Sprintf("%steam-collabs-1-%s", testResourcePrefix, randomID) + teamName2 := fmt.Sprintf("%steam-collabs-2-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -422,7 +423,7 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { ctx := t.Context() conn := meta.v3client randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) + repoName := fmt.Sprintf("%srepo-collabs-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -485,8 +486,8 @@ func TestAccGithubRepositoryCollaborators(t *testing.T) { ctx := t.Context() conn := meta.v3client randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) - teamName := fmt.Sprintf("tf-acc-test-team-%s", randomID) + repoName := fmt.Sprintf("%srepo-collabs-%s", testResourcePrefix, randomID) + teamName := fmt.Sprintf("%steam-collabs-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { diff --git a/github/resource_github_repository_custom_property_test.go b/github/resource_github_repository_custom_property_test.go index 7b8a4deae7..3121f52d00 100644 --- a/github/resource_github_repository_custom_property_test.go +++ b/github/resource_github_repository_custom_property_test.go @@ -11,6 +11,7 @@ import ( func TestAccGithubRepositoryCustomProperty(t *testing.T) { t.Run("creates custom property of type single_select without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-custom-prop-%s", testResourcePrefix, randomID) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) config := fmt.Sprintf(` @@ -21,7 +22,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { value_type = "single_select" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -30,7 +31,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { property_type = github_organization_custom_properties.test.value_type property_value = ["option1"] } - `, propertyName, randomID) + `, propertyName, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_name", propertyName), @@ -52,6 +53,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { t.Run("creates custom property of type multi_select without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-custom-prop-%s", testResourcePrefix, randomID) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) config := fmt.Sprintf(` @@ -62,7 +64,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { value_type = "multi_select" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -71,7 +73,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { property_type = github_organization_custom_properties.test.value_type property_value = ["option1", "option2"] } - `, propertyName, randomID) + `, propertyName, repoName) checkWithOwner := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_name", propertyName), @@ -94,6 +96,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { t.Run("creates custom property of type true-false without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-custom-prop-%s", testResourcePrefix, randomID) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) config := fmt.Sprintf(` @@ -103,7 +106,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { value_type = "true_false" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -112,7 +115,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { property_type = github_organization_custom_properties.test.value_type property_value = ["true"] } - `, propertyName, randomID) + `, propertyName, repoName) checkWithOwner := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_name", propertyName), @@ -134,6 +137,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { t.Run("creates custom property of type string without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-custom-prop-%s", testResourcePrefix, randomID) propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) config := fmt.Sprintf(` @@ -143,7 +147,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { value_type = "string" } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } resource "github_repository_custom_property" "test" { @@ -152,7 +156,7 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { property_type = github_organization_custom_properties.test.value_type property_value = ["text"] } - `, propertyName, randomID) + `, propertyName, repoName) checkWithOwner := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_name", propertyName), diff --git a/github/resource_github_repository_dependabot_security_updates_test.go b/github/resource_github_repository_dependabot_security_updates_test.go index 7308473b97..6b42a602c7 100644 --- a/github/resource_github_repository_dependabot_security_updates_test.go +++ b/github/resource_github_repository_dependabot_security_updates_test.go @@ -12,12 +12,13 @@ import ( func TestAccGithubRepositoryDependabotSecurityUpdates(t *testing.T) { t.Run("enables automated security fixes without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-depbot-updates-%s", testResourcePrefix, randomID) enabled := "enabled = false" updatedEnabled := "enabled = true" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" auto_init = true vulnerability_alerts = true @@ -28,7 +29,7 @@ func TestAccGithubRepositoryDependabotSecurityUpdates(t *testing.T) { repository = github_repository.test.id %s } - `, randomID, enabled) + `, repoName, enabled) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -65,13 +66,14 @@ func TestAccGithubRepositoryDependabotSecurityUpdates(t *testing.T) { t.Run("disables automated security fixes without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-depbot-updates-%s", testResourcePrefix, randomID) enabled := "enabled = true" updatedEnabled := "enabled = false" config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" auto_init = true vulnerability_alerts = true @@ -82,7 +84,7 @@ func TestAccGithubRepositoryDependabotSecurityUpdates(t *testing.T) { repository = github_repository.test.id %s } - `, randomID, enabled) + `, repoName, enabled) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -119,9 +121,10 @@ func TestAccGithubRepositoryDependabotSecurityUpdates(t *testing.T) { t.Run("imports automated security fixes without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-depbot-updates-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" vulnerability_alerts = true } @@ -129,7 +132,7 @@ func TestAccGithubRepositoryDependabotSecurityUpdates(t *testing.T) { repository = github_repository.test.id enabled = false } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_repository_dependabot_security_updates.test", "repository"), diff --git a/github/resource_github_repository_deploy_key_test.go b/github/resource_github_repository_deploy_key_test.go index f89e396e0a..c38317b8bc 100644 --- a/github/resource_github_repository_deploy_key_test.go +++ b/github/resource_github_repository_deploy_key_test.go @@ -62,7 +62,7 @@ func TestAccGithubRepositoryDeployKey_basic(t *testing.T) { rn := "github_repository_deploy_key.test_repo_deploy_key" rs := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) - repositoryName := fmt.Sprintf("acctest-%s", rs) + repositoryName := fmt.Sprintf("%srepo-deploy-key-%s", testResourcePrefix, rs) keyPath := strings.ReplaceAll(filepath.Join("test-fixtures", fmt.Sprintf("%s.pub", keyName)), "\\", "/") resource.Test(t, resource.TestCase{ @@ -180,10 +180,11 @@ func TestAccGithubRepositoryDeployKeyArchivedRepo(t *testing.T) { } keyPath := strings.ReplaceAll(filepath.Join("test-fixtures", fmt.Sprintf("%s.pub", keyName)), "\\", "/") + repoName := fmt.Sprintf("%srepo-deploy-key-arch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-deploy-key-archive-%s" + name = "%s" auto_init = true } @@ -193,11 +194,11 @@ func TestAccGithubRepositoryDeployKeyArchivedRepo(t *testing.T) { repository = github_repository.test.name title = "test-archived-deploy-key" } - `, randomID, keyPath) + `, repoName, keyPath) archivedConfig := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-deploy-key-archive-%s" + name = "%s" auto_init = true archived = true } @@ -208,7 +209,7 @@ func TestAccGithubRepositoryDeployKeyArchivedRepo(t *testing.T) { repository = github_repository.test.name title = "test-archived-deploy-key" } - `, randomID, keyPath) + `, repoName, keyPath) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -235,11 +236,11 @@ func TestAccGithubRepositoryDeployKeyArchivedRepo(t *testing.T) { { Config: fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-deploy-key-archive-%s" + name = "%s" auto_init = true archived = true } - `, randomID), + `, repoName), }, }, }) diff --git a/github/resource_github_repository_deployment_branch_policy_test.go b/github/resource_github_repository_deployment_branch_policy_test.go index bdbd013be2..403911619d 100644 --- a/github/resource_github_repository_deployment_branch_policy_test.go +++ b/github/resource_github_repository_deployment_branch_policy_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryDeploymentBranchPolicy(t *testing.T) { t.Run("creates deployment branch policy", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-deploy-bp-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -26,7 +27,7 @@ func TestAccGithubRepositoryDeploymentBranchPolicy(t *testing.T) { custom_branch_policies = true } } - `, randomID) + `, repoName) config1 := ` resource "github_repository_deployment_branch_policy" "br" { diff --git a/github/resource_github_repository_environment_deployment_policy_test.go b/github/resource_github_repository_environment_deployment_policy_test.go index 6cbcd3f607..d3cc2a1592 100644 --- a/github/resource_github_repository_environment_deployment_policy_test.go +++ b/github/resource_github_repository_environment_deployment_policy_test.go @@ -11,9 +11,9 @@ import ( ) func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranch(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("creates a repository environment with branch-based deployment policy", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` data "github_user" "current" { @@ -21,7 +21,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranch(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -44,12 +44,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranch(t *testing.T) { branch_pattern = "releases/*" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -78,9 +78,9 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranch(t *testing.T) { } func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchUpdate(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("updates the pattern for a branch-based deployment policy", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) var deploymentPolicyId string config1 := fmt.Sprintf(` @@ -90,7 +90,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchUpdate(t *testing.T } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -113,12 +113,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchUpdate(t *testing.T branch_pattern = "main" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -141,7 +141,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchUpdate(t *testing.T } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -164,10 +164,10 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchUpdate(t *testing.T branch_pattern = "release/*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "repository", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "repository", repoName), resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "environment", "environment/test"), resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "branch_pattern", "release/*"), resource.TestCheckNoResourceAttr("github_repository_environment_deployment_policy.test", "tag_pattern"), @@ -195,9 +195,9 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchUpdate(t *testing.T } func TestAccGithubRepositoryEnvironmentDeploymentPolicyTag(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("creates a repository environment with tag-based deployment policy", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` data "github_user" "current" { @@ -205,7 +205,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTag(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -228,12 +228,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTag(t *testing.T) { tag_pattern = "v*" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -262,9 +262,9 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTag(t *testing.T) { } func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagUpdate(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("updates the pattern for a tag-based deployment policy", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) var deploymentPolicyId string config1 := fmt.Sprintf(` @@ -274,7 +274,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagUpdate(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -297,12 +297,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagUpdate(t *testing.T) { tag_pattern = "v*" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -325,7 +325,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagUpdate(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -348,12 +348,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagUpdate(t *testing.T) { tag_pattern = "version*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -390,9 +390,9 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagUpdate(t *testing.T) { } func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchToTagUpdate(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("recreates deployment policy when pattern type changes from branch to tag", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) var deploymentPolicyId string config1 := fmt.Sprintf(` @@ -402,7 +402,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchToTagUpdate(t *test } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -425,12 +425,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchToTagUpdate(t *test branch_pattern = "release/*" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -453,7 +453,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchToTagUpdate(t *test } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -476,12 +476,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchToTagUpdate(t *test tag_pattern = "v*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -518,9 +518,9 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyBranchToTagUpdate(t *test } func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagToBranchUpdate(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("recreates deployment policy when pattern type changes from tag to branch", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) var deploymentPolicyId string config1 := fmt.Sprintf(` @@ -530,7 +530,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagToBranchUpdate(t *test } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -553,12 +553,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagToBranchUpdate(t *test tag_pattern = "v*" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -581,7 +581,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagToBranchUpdate(t *test } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -604,12 +604,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagToBranchUpdate(t *test branch_pattern = "release/*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -648,9 +648,10 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyTagToBranchUpdate(t *test func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { t.Run("errors when no patterns are set", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -667,7 +668,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { repository = github_repository.test.name environment = github_repository_environment.test.environment } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -683,9 +684,10 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { t.Run("errors when both patterns are set", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -704,7 +706,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { branch_pattern = "main" tag_pattern = "v*" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -720,9 +722,10 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { t.Run("errors when an empty branch pattern is set", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -740,7 +743,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { environment = github_repository_environment.test.environment branch_pattern = "" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -756,9 +759,10 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { t.Run("errors when an empty tag pattern is set", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -776,7 +780,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { environment = github_repository_environment.test.environment tag_pattern = "" } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -794,6 +798,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicyErrors(t *testing.T) { func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { t.Run("creates a repository environment with branch-based deployment policy", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` data "github_user" "current" { @@ -801,7 +806,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -824,12 +829,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { branch_pattern = "releases/*" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -858,6 +863,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { t.Run("updates the pattern for a branch-based deployment policy", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) var deploymentPolicyId string config1 := fmt.Sprintf(` @@ -867,7 +873,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -890,12 +896,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { branch_pattern = "main" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -918,7 +924,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -941,10 +947,10 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { branch_pattern = "release/*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "repository", fmt.Sprintf("tf-acc-test-%s", randomID)), + resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "repository", repoName), resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "environment", "environment/test"), resource.TestCheckResourceAttr("github_repository_environment_deployment_policy.test", "branch_pattern", "release/*"), resource.TestCheckNoResourceAttr("github_repository_environment_deployment_policy.test", "tag_pattern"), @@ -972,6 +978,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { t.Run("creates a repository environment with tag-based deployment policy", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` data "github_user" "current" { @@ -979,7 +986,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1002,12 +1009,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { tag_pattern = "v*" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -1037,6 +1044,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { t.Run("updates the pattern for a tag-based deployment policy", func(t *testing.T) { var deploymentPolicyId string randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config1 := fmt.Sprintf(` @@ -1045,7 +1053,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1068,12 +1076,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { tag_pattern = "v*" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -1096,7 +1104,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1119,12 +1127,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { tag_pattern = "version*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -1162,6 +1170,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { t.Run("recreates deployment policy when pattern type changes from branch to tag", func(t *testing.T) { var deploymentPolicyId string randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config1 := fmt.Sprintf(` @@ -1170,7 +1179,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1193,12 +1202,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { branch_pattern = "release/*" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -1221,7 +1230,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1244,12 +1253,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { tag_pattern = "v*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -1287,6 +1296,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { t.Run("recreates deployment policy when pattern type changes from tag to branch", func(t *testing.T) { var deploymentPolicyId string randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-deploy-%s", testResourcePrefix, randomID) config1 := fmt.Sprintf(` @@ -1295,7 +1305,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1318,12 +1328,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { tag_pattern = "v*" } - `, randomID) + `, repoName) check1 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", @@ -1346,7 +1356,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" ignore_vulnerability_alerts_during_read = true } @@ -1369,12 +1379,12 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) { branch_pattern = "release/*" } - `, randomID) + `, repoName) check2 := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr( "github_repository_environment_deployment_policy.test", "environment", diff --git a/github/resource_github_repository_environment_test.go b/github/resource_github_repository_environment_test.go index addcfeb42d..16d2beb148 100644 --- a/github/resource_github_repository_environment_test.go +++ b/github/resource_github_repository_environment_test.go @@ -11,6 +11,7 @@ import ( func TestAccGithubRepositoryEnvironment(t *testing.T) { t.Run("creates a repository environment", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-env-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` data "github_user" "current" { @@ -18,7 +19,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) { } resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "public" } @@ -37,7 +38,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) { } } - `, randomID) + `, repoName) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("github_repository_environment.test", "environment", "environment / test"), diff --git a/github/resource_github_repository_file_test.go b/github/resource_github_repository_file_test.go index 8c389bf454..0c5c05d01f 100644 --- a/github/resource_github_repository_file_test.go +++ b/github/resource_github_repository_file_test.go @@ -12,10 +12,12 @@ import ( func TestAccGithubRepositoryFile(t *testing.T) { t.Run("creates and manages files", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true vulnerability_alerts = true } @@ -29,7 +31,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_author = "Terraform User" commit_email = "terraform@example.com" } - `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_file.test", "content", @@ -73,9 +75,11 @@ func TestAccGithubRepositoryFile(t *testing.T) { }) t.Run("can be configured to overwrite files on create", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true vulnerability_alerts = true } @@ -91,7 +95,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_email = "terraform@example.com" } - `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -138,10 +142,12 @@ func TestAccGithubRepositoryFile(t *testing.T) { }) t.Run("creates and manages files on default branch if branch is omitted", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true vulnerability_alerts = true } @@ -154,7 +160,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_author = "Terraform User" commit_email = "terraform@example.com" } - `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -199,9 +205,11 @@ func TestAccGithubRepositoryFile(t *testing.T) { }) t.Run("creates and manages files on auto created branch if branch does not exist", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true vulnerability_alerts = true } @@ -216,7 +224,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_email = "terraform@example.com" autocreate_branch = false } - `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -267,9 +275,11 @@ func TestAccGithubRepositoryFile(t *testing.T) { }) t.Run("can delete files from archived repositories without error", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-file-arch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-file-archive-%s" + name = "%s" auto_init = true } @@ -282,7 +292,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_author = "Terraform User" commit_email = "terraform@example.com" } - `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) + `, repoName) archivedConfig := strings.Replace(config, `auto_init = true`, @@ -316,11 +326,11 @@ func TestAccGithubRepositoryFile(t *testing.T) { { Config: fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-file-archive-%s" + name = "%s" auto_init = true archived = true } - `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)), + `, repoName), }, }, }) diff --git a/github/resource_github_repository_milestone_test.go b/github/resource_github_repository_milestone_test.go index ebede46eed..30346b94f7 100644 --- a/github/resource_github_repository_milestone_test.go +++ b/github/resource_github_repository_milestone_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryMilestone(t *testing.T) { t.Run("creates a repository milestone", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-milestone-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" } resource "github_repository_milestone" "test" { @@ -26,7 +27,7 @@ func TestAccGithubRepositoryMilestone(t *testing.T) { state = "closed" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( diff --git a/github/resource_github_repository_project_test.go b/github/resource_github_repository_project_test.go index 3c77fc0122..8ea8d8ce1e 100644 --- a/github/resource_github_repository_project_test.go +++ b/github/resource_github_repository_project_test.go @@ -14,10 +14,11 @@ func TestAccGithubRepositoryProject(t *testing.T) { t.Run("creates a repository project", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-project-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" has_projects = true } @@ -26,12 +27,12 @@ func TestAccGithubRepositoryProject(t *testing.T) { repository = github_repository.test.name body = "this is a test project" } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr( "github_repository_project.test", "url", - regexp.MustCompile(randomID+"/projects/1"), + regexp.MustCompile(repoName+"/projects/1"), ), ) diff --git a/github/resource_github_repository_pull_request_test.go b/github/resource_github_repository_pull_request_test.go index b1f964c7c5..816abd8a07 100644 --- a/github/resource_github_repository_pull_request_test.go +++ b/github/resource_github_repository_pull_request_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryPullRequest(t *testing.T) { t.Run("manages the pull request lifecycle", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-pr-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -38,14 +39,14 @@ func TestAccGithubRepositoryPullRequest(t *testing.T) { title = "test title" body = "test body" } - `, randomID) + `, repoName) const resourceName = "github_repository_pull_request.test" check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( resourceName, "base_repository", - fmt.Sprintf("tf-acc-test-%s", randomID), + repoName, ), resource.TestCheckResourceAttr(resourceName, "base_ref", "main"), resource.TestCheckResourceAttr(resourceName, "head_ref", "test"), diff --git a/github/resource_github_repository_ruleset_test.go b/github/resource_github_repository_ruleset_test.go index 6bdce3117d..54161a0af0 100644 --- a/github/resource_github_repository_ruleset_test.go +++ b/github/resource_github_repository_ruleset_test.go @@ -15,10 +15,11 @@ import ( func TestAccGithubRepositoryRuleset(t *testing.T) { t.Run("create_branch_ruleset", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true default_branch = "main" vulnerability_alerts = true @@ -106,7 +107,7 @@ resource "github_repository_ruleset" "test" { } } } -`, randomID) +`, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -135,10 +136,11 @@ resource "github_repository_ruleset" "test" { t.Run("create_branch_ruleset_with_enterprise_features", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = false vulnerability_alerts = true } @@ -170,7 +172,7 @@ resource "github_repository_ruleset" "test" { } } } -`, randomID) +`, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessMode(t, enterprise) }, @@ -189,10 +191,11 @@ resource "github_repository_ruleset" "test" { t.Run("creates_push_ruleset", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = false visibility = "internal" vulnerability_alerts = true @@ -230,7 +233,7 @@ resource "github_repository_ruleset" "test" { } } -`, randomID) +`, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasPaidOrgs(t) }, @@ -259,7 +262,7 @@ resource "github_repository_ruleset" "test" { t.Run("update_ruleset_name", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf(`tf-acc-test-rename-%[1]s`, randomID) + repoName := fmt.Sprintf("%srepo-ruleset-rename-%s", testResourcePrefix, randomID) name := fmt.Sprintf(`ruleset-%[1]s`, randomID) nameUpdated := fmt.Sprintf(`%[1]s-renamed`, randomID) @@ -304,10 +307,11 @@ resource "github_repository_ruleset" "test" { t.Run("update_clear_bypass_actors", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-bypass-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-bypass-%s" + name = "%s" description = "Terraform acceptance tests %[1]s" auto_init = true } @@ -340,11 +344,11 @@ resource "github_repository_ruleset" "test" { creation = true } } -`, randomID) +`, repoName) configUpdated := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-bypass-%s" + name = "%s" description = "Terraform acceptance tests %[1]s" auto_init = true } @@ -366,7 +370,7 @@ resource "github_repository_ruleset" "test" { creation = true } } -`, randomID) +`, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -390,14 +394,15 @@ resource "github_repository_ruleset" "test" { t.Run("update_bypass_mode", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-bypass-update-%s", testResourcePrefix, randomID) bypassMode := "always" bypassModeUpdated := "exempt" - config := ` + config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-bypass-update-%s" - description = "Terraform acceptance tests %[1]s" + name = "%s" + description = "Terraform acceptance tests %s" auto_init = true } @@ -424,7 +429,7 @@ resource "github_repository_ruleset" "test" { creation = true } } -` +`, repoName, randomID, bypassMode) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -448,11 +453,12 @@ resource "github_repository_ruleset" "test" { t.Run("import", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-bpmod-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-import-%[1]s" - description = "Terraform acceptance tests %[1]s" + name = "%s" + description = "Terraform acceptance tests %s" auto_init = true default_branch = "main" vulnerability_alerts = true @@ -480,7 +486,7 @@ resource "github_repository_ruleset" "test" { creation = true } } - `, randomID) + `, repoName, randomID) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -502,12 +508,12 @@ resource "github_repository_ruleset" "test" { } func TestAccGithubRepositoryRulesetArchived(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("skips update and delete on archived repository", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-arch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-archive-%s" + name = "%s" auto_init = true archived = false } @@ -519,7 +525,7 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) { enforcement = "active" rules { creation = true } } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessMode(t, individual) }, @@ -533,9 +539,11 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) { }) t.Run("prevents creating ruleset on archived repository", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-ruleset-arch-cr-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-archive-create-%s" + name = "%s" auto_init = true archived = true } @@ -546,7 +554,7 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) { enforcement = "active" rules { creation = true } } - `, randomID) + `, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessMode(t, individual) }, diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index b51ccc05b9..9bfde4fd9a 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -18,10 +18,11 @@ import ( func TestAccGithubRepository(t *testing.T) { t.Run("creates and updates repositories without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%screate-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-create-%[1]s" + name = "%s" description = "Terraform acceptance tests %[1]s" has_discussions = true has_issues = true @@ -36,7 +37,7 @@ func TestAccGithubRepository(t *testing.T) { auto_init = false web_commit_signoff_required = true } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -75,13 +76,13 @@ func TestAccGithubRepository(t *testing.T) { t.Run("updates a repositories name without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - oldName := fmt.Sprintf(`tf-acc-test-rename-%[1]s`, randomID) - newName := fmt.Sprintf(`%[1]s-renamed`, oldName) + oldName := fmt.Sprintf(`%srename-%s`, testResourcePrefix, randomID) + newName := fmt.Sprintf(`%s-renamed`, oldName) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "%[1]s" - description = "Terraform acceptance tests %[2]s" + name = "%[1]s" + description = "Terraform acceptance tests %[2]s" } `, oldName, randomID) @@ -130,13 +131,14 @@ func TestAccGithubRepository(t *testing.T) { t.Run("imports repositories without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%simport-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-import-%[1]s" - description = "Terraform acceptance tests %[1]s" + name = "%s" + description = "Terraform acceptance tests %[1]s" auto_init = false } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_repository.test", "name"), @@ -161,13 +163,14 @@ func TestAccGithubRepository(t *testing.T) { t.Run("archives repositories without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sarchive-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-archive-%[1]s" - description = "Terraform acceptance tests %[1]s" + name = "%s" + description = "Terraform acceptance tests %[1]s" archived = false } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -204,13 +207,14 @@ func TestAccGithubRepository(t *testing.T) { t.Run("manages the project feature for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sproject-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-project-%[1]s" - description = "Terraform acceptance tests %[1]s" + name = "%s" + description = "Terraform acceptance tests %[1]s" has_projects = false } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -247,19 +251,20 @@ func TestAccGithubRepository(t *testing.T) { t.Run("manages the default branch feature for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sbranch-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-branch-%[1]s" - description = "Terraform acceptance tests %[1]s" - default_branch = "main" - auto_init = true + name = "%s" + description = "Terraform acceptance tests %[1]s" + default_branch = "main" + auto_init = true } resource "github_branch" "default" { - repository = github_repository.test.name - branch = "default" + repository = github_repository.test.name + branch = "default" } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -305,13 +310,14 @@ func TestAccGithubRepository(t *testing.T) { // we allow setting it to "main". randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sempty-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-empty-%[1]s" - description = "Terraform acceptance tests %[1]s" - default_branch = "main" + name = "%s" + description = "Terraform acceptance tests %[1]s" + default_branch = "main" } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -343,14 +349,15 @@ func TestAccGithubRepository(t *testing.T) { t.Run("manages the license and gitignore feature for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%slicense-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-license-%[1]s" + name = "%s" description = "Terraform acceptance tests %[1]s" license_template = "ms-pl" gitignore_template = "C++" } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -377,13 +384,14 @@ func TestAccGithubRepository(t *testing.T) { t.Run("configures topics for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%stopic-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -406,9 +414,10 @@ func TestAccGithubRepository(t *testing.T) { t.Run("creates a repository using a public template", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%stemplate-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-template-%s" + name = "%s" description = "Terraform acceptance tests %[1]s" template { @@ -417,7 +426,7 @@ func TestAccGithubRepository(t *testing.T) { } } - `, randomID, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository) + `, testRepoName, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -440,9 +449,10 @@ func TestAccGithubRepository(t *testing.T) { t.Run("creates a repository using an org template", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%stemplate-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-template-%s" + name = "%s" description = "Terraform acceptance tests %[1]s" template { @@ -451,7 +461,7 @@ func TestAccGithubRepository(t *testing.T) { } } - `, randomID, testAccConf.owner, testAccConf.testOrgTemplateRepository) + `, testRepoName, testAccConf.owner, testAccConf.testOrgTemplateRepository) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -474,14 +484,15 @@ func TestAccGithubRepository(t *testing.T) { t.Run("archives repositories on destroy", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sdestroy-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-destroy-%[1]s" + name = "%s" auto_init = true archive_on_destroy = true archived = false } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -518,7 +529,7 @@ func TestAccGithubRepository(t *testing.T) { t.Run("configures vulnerability alerts for a public repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-pub-vuln-%s", randomID) + repoName := fmt.Sprintf("%spub-vuln-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -560,7 +571,7 @@ func TestAccGithubRepository(t *testing.T) { t.Run("create_private_with_forking", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-%s", randomID) + repoName := fmt.Sprintf("%svisibility-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -588,7 +599,7 @@ func TestAccGithubRepository(t *testing.T) { t.Run("configures vulnerability alerts for a private repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("tf-acc-test-prv-vuln-%s", randomID) + repoName := fmt.Sprintf("%sprv-vuln-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -630,6 +641,7 @@ func TestAccGithubRepository(t *testing.T) { t.Run("create and modify merge commit strategy without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%smodify-co-str-%s", testResourcePrefix, randomID) mergeCommitTitle := "PR_TITLE" mergeCommitMessage := "BLANK" updatedMergeCommitTitle := "MERGE_MESSAGE" @@ -637,22 +649,22 @@ func TestAccGithubRepository(t *testing.T) { configs := map[string]string{ "before": fmt.Sprintf(` - resource "github_repository" "test" { - - name = "tf-acc-test-modify-co-str-%[1]s" - allow_merge_commit = true - merge_commit_title = "%s" - merge_commit_message = "%s" - } - `, randomID, mergeCommitTitle, mergeCommitMessage), + resource "github_repository" "test" { + + name = "%[1]s" + allow_merge_commit = true + merge_commit_title = "%s" + merge_commit_message = "%s" + } + `, testRepoName, mergeCommitTitle, mergeCommitMessage), "after": fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-co-str-%[1]s" - allow_merge_commit = true - merge_commit_title = "%s" - merge_commit_message = "%s" - } - `, randomID, updatedMergeCommitTitle, updatedMergeCommitMessage), + resource "github_repository" "test" { + name = "%[1]s" + allow_merge_commit = true + merge_commit_title = "%s" + merge_commit_message = "%s" + } + `, testRepoName, updatedMergeCommitTitle, updatedMergeCommitMessage), } checks := map[string]resource.TestCheckFunc{ @@ -696,6 +708,8 @@ func TestAccGithubRepository(t *testing.T) { t.Run("create and modify squash merge commit strategy without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%smodify-sq-str-%s", testResourcePrefix, randomID) + testRepoNameAfter := fmt.Sprintf("%s-modified", testRepoName) squashMergeCommitTitle := "PR_TITLE" squashMergeCommitMessage := "PR_BODY" updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" @@ -703,21 +717,21 @@ func TestAccGithubRepository(t *testing.T) { configs := map[string]string{ "before": fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-sq-str-%[1]s" - allow_squash_merge = true - squash_merge_commit_title = "%s" - squash_merge_commit_message = "%s" - } - `, randomID, squashMergeCommitTitle, squashMergeCommitMessage), + resource "github_repository" "test" { + name = "%s" + allow_squash_merge = true + squash_merge_commit_title = "%s" + squash_merge_commit_message = "%s" + } + `, testRepoName, squashMergeCommitTitle, squashMergeCommitMessage), "after": fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-sq-str-%[1]s" - allow_squash_merge = true - squash_merge_commit_title = "%s" - squash_merge_commit_message = "%s" - } - `, randomID, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), + resource "github_repository" "test" { + name = "%s" + allow_squash_merge = true + squash_merge_commit_title = "%s" + squash_merge_commit_message = "%s" + } + `, testRepoNameAfter, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), } checks := map[string]resource.TestCheckFunc{ @@ -761,9 +775,10 @@ func TestAccGithubRepository(t *testing.T) { // t.Run("create a repository with go as primary_language", func(t *testing.T) { // randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + // testResourceName := fmt.Sprintf("%srepo-%s", testResourcePrefix, randomID) // config := fmt.Sprintf(` // resource "github_repository" "test" { - // name = "tf-acc-%s" + // name = "%s" // auto_init = true // } // resource "github_repository_file" "test" { @@ -771,7 +786,7 @@ func TestAccGithubRepository(t *testing.T) { // file = "test.go" // content = "package main" // } - // `, randomID) + // `, testResourceName) // check := resource.ComposeTestCheckFunc( // resource.TestCheckResourceAttr("github_repository.test", "primary_language", "Go"), @@ -796,9 +811,10 @@ func TestAccGithubRepository(t *testing.T) { t.Run("manages the legacy pages feature for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%slegacy-pages-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" auto_init = true pages { build_type = "legacy" @@ -808,7 +824,7 @@ func TestAccGithubRepository(t *testing.T) { } } } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -827,15 +843,16 @@ func TestAccGithubRepository(t *testing.T) { t.Run("manages the pages from workflow feature for a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sworkflow-pages-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" + name = "%s" auto_init = true pages { build_type = "workflow" } } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -857,33 +874,34 @@ func TestAccGithubRepository(t *testing.T) { } randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%ssecurity-private-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" - description = "A repository created by Terraform to test security features" - visibility = "private" - security_and_analysis { - advanced_security { - status = "enabled" - } - code_security { - status = "enabled" - } - secret_scanning { - status = "enabled" - } - secret_scanning_push_protection { - status = "enabled" - } - secret_scanning_ai_detection { - status = "enabled" - } - secret_scanning_non_provider_patterns { - status = "enabled" - } - } + name = "%s" + description = "A repository created by Terraform to test security features" + visibility = "private" + security_and_analysis { + advanced_security { + status = "enabled" + } + code_security { + status = "enabled" + } + secret_scanning { + status = "enabled" + } + secret_scanning_push_protection { + status = "enabled" + } + secret_scanning_ai_detection { + status = "enabled" + } + secret_scanning_non_provider_patterns { + status = "enabled" + } + } } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -925,22 +943,23 @@ func TestAccGithubRepository(t *testing.T) { t.Run("manages the security feature for a public repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%ssecurity-public-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-%s" - description = "A repository created by Terraform to test security features" - visibility = "public" - security_and_analysis { - secret_scanning { - status = "enabled" - } - # seems like it can only be "enabled" for an organization that has purchased GHAS - secret_scanning_push_protection { - status = "disabled" - } - } + name = "%s" + description = "A repository created by Terraform to test security features" + visibility = "public" + security_and_analysis { + secret_scanning { + status = "enabled" + } + # seems like it can only be "enabled" for an organization that has purchased GHAS + secret_scanning_push_protection { + status = "disabled" + } + } } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -966,12 +985,13 @@ func TestAccGithubRepository(t *testing.T) { t.Run("creates repos with private visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svisibility-private-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "private" { - name = "tf-acc-test-visibility-private-%s" + name = "%s" visibility = "private" } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -994,12 +1014,13 @@ func TestAccGithubRepository(t *testing.T) { t.Run("creates repos with internal visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svisibility-internal-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "internal" { - name = "tf-acc-test-visibility-internal-%s" + name = "%s" visibility = "internal" } - `, randomID) + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -1022,13 +1043,14 @@ func TestAccGithubRepository(t *testing.T) { t.Run("updates repos to private visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svisibility-public-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "public" { - name = "tf-acc-test-visibility-public-%s" + name = "%s" visibility = "public" vulnerability_alerts = false } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -1063,28 +1085,29 @@ func TestAccGithubRepository(t *testing.T) { t.Run("update_public_to_private_allow_forking", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svisibility-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "public" } - `, randomID) + `, testRepoName) configPrivate := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" allow_forking = false } - `, randomID) + `, testRepoName) configPrivateForking := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" visibility = "private" allow_forking = true } - `, randomID) + `, testRepoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -1117,12 +1140,13 @@ func TestAccGithubRepository(t *testing.T) { t.Run("updates repos to public visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%spublic-vuln-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-prv-vuln-%s" + resource "github_repository" "test" { + name = "%s" visibility = "private" } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -1163,12 +1187,13 @@ func TestAccGithubRepository(t *testing.T) { t.Run("updates repos to internal visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sinternal-vuln-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-prv-vuln-%s" + name = "%s" visibility = "private" } - `, randomID) + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -1209,16 +1234,17 @@ func TestAccGithubRepository(t *testing.T) { t.Run("sets private visibility for repositories created by a template", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%stemplate-visibility-private-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "private" { - name = "tf-acc-test-visibility-private-%s" + name = "%s" visibility = "private" template { owner = "%s" repository = "%s" } } - `, randomID, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository) + `, testRepoName, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -1390,18 +1416,18 @@ func TestGithubRepositoryNameFailsValidationWithSpace(t *testing.T) { } func TestAccGithubRepository_fork(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("forks a repository without error", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sfork-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` - resource "github_repository" "forked" { - name = "terraform-provider-github-%s" + resource "github_repository" "forked" { + name = "%s" description = "Terraform acceptance test - forked repository %[1]s" fork = true source_owner = "integrations" source_repo = "terraform-provider-github" - } - `, randomID) + } + `, testRepoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -1435,29 +1461,31 @@ func TestAccGithubRepository_fork(t *testing.T) { }) t.Run("can update forked repository properties", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sfork-update-%s", testResourcePrefix, randomID) initialConfig := fmt.Sprintf(` - resource "github_repository" "forked_update" { - name = "terraform-provider-github-update-%s" + resource "github_repository" "forked_update" { + name = "%s" description = "Initial description for forked repo" fork = true source_owner = "integrations" source_repo = "terraform-provider-github" has_wiki = true has_issues = false - } - `, randomID) + } + `, testRepoName) updatedConfig := fmt.Sprintf(` - resource "github_repository" "forked_update" { - name = "terraform-provider-github-update-%s" + resource "github_repository" "forked_update" { + name = "%s" description = "Updated description for forked repo" fork = true source_owner = "integrations" source_repo = "terraform-provider-github" has_wiki = false has_issues = true - } - `, randomID) + } + `, testRepoName) checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( @@ -1612,16 +1640,16 @@ func TestAccGithubRepository_fork(t *testing.T) { // } func TestAccRepository_VulnerabilityAlerts(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - t.Run("can enable vulnerability alerts", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svulnerability-alerts-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-vuln-%s" - description = "Terraform acceptance test - repository %[1]s" + name = "%s" + description = "Terraform acceptance test - repository %s" vulnerability_alerts = true } - `, randomID) + `, testRepoName, randomID) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -1641,12 +1669,14 @@ func TestAccRepository_VulnerabilityAlerts(t *testing.T) { }) t.Run("sets vulnerability alerts to false when not set in config", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svulnerability-alerts-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-vuln-%s" - description = "Terraform acceptance test - repository %[1]s" + name = "%s" + description = "Terraform acceptance test - repository %s" } - `, randomID) + `, testRepoName, randomID) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -1665,13 +1695,15 @@ func TestAccRepository_VulnerabilityAlerts(t *testing.T) { }) t.Run("can disable vulnerability alerts", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svulnerability-alerts-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-vuln-%s" - description = "Terraform acceptance test - repository %[1]s" + name = "%s" + description = "Terraform acceptance test - repository %s" vulnerability_alerts = false } - `, randomID) + `, testRepoName, randomID) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, @@ -1691,13 +1723,15 @@ func TestAccRepository_VulnerabilityAlerts(t *testing.T) { }) t.Run("can modify vulnerability alerts", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%svulnerability-alerts-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-vuln-%s" - description = "Terraform acceptance test - repository %[1]s" + name = "%s" + description = "Terraform acceptance test - repository %s" vulnerability_alerts = false } - `, randomID) + `, testRepoName, randomID) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_repository_topics_test.go b/github/resource_github_repository_topics_test.go index 1548a49a35..69f9a0f216 100644 --- a/github/resource_github_repository_topics_test.go +++ b/github/resource_github_repository_topics_test.go @@ -11,10 +11,11 @@ import ( func TestAccGithubRepositoryTopics(t *testing.T) { t.Run("create repository topics and import them", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-topics-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -22,7 +23,7 @@ func TestAccGithubRepositoryTopics(t *testing.T) { repository = github_repository.test.name topics = ["test", "test-2"] } - `, randomID) + `, repoName) const resourceName = "github_repository_topics.test" @@ -49,10 +50,11 @@ func TestAccGithubRepositoryTopics(t *testing.T) { t.Run("create repository topics and update them", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-topics-%s", testResourcePrefix, randomID) configBefore := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -60,11 +62,11 @@ func TestAccGithubRepositoryTopics(t *testing.T) { repository = github_repository.test.name topics = ["test", "test-2"] } - `, randomID) + `, repoName) configAfter := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-%s" + name = "%s" auto_init = true } @@ -72,7 +74,7 @@ func TestAccGithubRepositoryTopics(t *testing.T) { repository = github_repository.test.name topics = ["test", "test-2", "extra-topic"] } - `, randomID) + `, repoName) const resourceName = "github_repository_topics.test" diff --git a/github/resource_github_repository_webhook_test.go b/github/resource_github_repository_webhook_test.go index 8105f2e259..11eb1f0ce4 100644 --- a/github/resource_github_repository_webhook_test.go +++ b/github/resource_github_repository_webhook_test.go @@ -11,15 +11,16 @@ import ( func TestAccGithubRepositoryWebhook(t *testing.T) { t.Run("creates repository webhooks without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-webhook-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests" } resource "github_repository_webhook" "test" { depends_on = [github_repository.test] - repository = "test-%[1]s" + repository = "%[1]s" configuration { url = "https://google.de/webhook" @@ -29,7 +30,7 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { events = ["pull_request"] } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -54,15 +55,16 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { t.Run("imports repository webhooks without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-webhook-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests" } resource "github_repository_webhook" "test" { depends_on = [github_repository.test] - repository = "test-%[1]s" + repository = "%[1]s" configuration { url = "https://google.de/webhook" content_type = "json" @@ -70,7 +72,7 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { } events = ["pull_request"] } - `, randomID) + `, repoName) check := resource.ComposeTestCheckFunc() @@ -86,7 +88,7 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { ResourceName: "github_repository_webhook.test", ImportState: true, ImportStateVerify: true, - ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID), + ImportStateIdPrefix: fmt.Sprintf("%s/", repoName), }, }, }) @@ -94,16 +96,17 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { t.Run("updates repository webhooks without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-webhook-%s", testResourcePrefix, randomID) configs := map[string]string{ "before": fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests" } resource "github_repository_webhook" "test" { depends_on = [github_repository.test] - repository = "test-%[1]s" + repository = "%[1]s" configuration { url = "https://google.de/webhook" @@ -113,16 +116,16 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { events = ["pull_request"] } - `, randomID), + `, repoName), "after": fmt.Sprintf(` resource "github_repository" "test" { - name = "test-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests" } resource "github_repository_webhook" "test" { depends_on = [github_repository.test] - repository = "test-%[1]s" + repository = "%[1]s" configuration { secret = "secret" @@ -133,7 +136,7 @@ func TestAccGithubRepositoryWebhook(t *testing.T) { events = ["pull_request"] } - `, randomID), + `, repoName), } checks := map[string]resource.TestCheckFunc{ diff --git a/github/resource_github_team_members_test.go b/github/resource_github_team_members_test.go index cbf964b6bb..b00a3709cd 100644 --- a/github/resource_github_team_members_test.go +++ b/github/resource_github_team_members_test.go @@ -17,7 +17,7 @@ func TestAccGithubTeamMembers(t *testing.T) { t.Run("creates a team & members configured with defaults", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - teamName := fmt.Sprintf("tf-acc-test-team-%s", randomID) + teamName := fmt.Sprintf("%steam-members-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { diff --git a/github/resource_github_team_membership_test.go b/github/resource_github_team_membership_test.go index 1b287678bc..f9156f349f 100644 --- a/github/resource_github_team_membership_test.go +++ b/github/resource_github_team_membership_test.go @@ -204,14 +204,16 @@ func testAccCheckGithubTeamMembershipRoleState(ctx context.Context, n, expected } func testAccGithubTeamMembershipConfig(randString, username, role string) string { + teamName := fmt.Sprintf("%steam-membership-%s", testResourcePrefix, randString) + teamSlugName := fmt.Sprintf("%s-slug", teamName) return fmt.Sprintf(` resource "github_team" "test_team" { - name = "tf-acc-test-team-membership-%s" + name = "%s" description = "Terraform acc test group" } resource "github_team" "test_team_slug" { - name = "tf-acc-test-team-membership-%s-slug" + name = "%s" description = "Terraform acc test group" } @@ -226,7 +228,7 @@ resource "github_team_membership" "test_team_membership_slug" { username = "%s" role = "%s" } -`, randString, randString, username, role, username, role) +`, teamName, teamSlugName, username, role, username, role) } func testAccGithubTeamMembershipTheSame(orig, other *github.Membership) resource.TestCheckFunc { diff --git a/github/resource_github_team_repository_test.go b/github/resource_github_team_repository_test.go index f7e3045200..718c1bfa99 100644 --- a/github/resource_github_team_repository_test.go +++ b/github/resource_github_team_repository_test.go @@ -12,14 +12,17 @@ import ( func TestAccGithubTeamRepository(t *testing.T) { t.Run("manages team permissions to a repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-repo-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-team-repo-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-repo-%s" + name = "%s" description = "test" } resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%s" } resource "github_team_repository" "test" { @@ -27,7 +30,7 @@ func TestAccGithubTeamRepository(t *testing.T) { repository = "${github_repository.test.name}" permission = "pull" } - `, randomID) + `, teamName, repoName) checks := map[string]resource.TestCheckFunc{ "pull": resource.ComposeTestCheckFunc( @@ -100,14 +103,17 @@ func TestAccGithubTeamRepository(t *testing.T) { t.Run("accepts both team slug and team ID for `team_id`", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-repo-slug-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-team-repo-slug-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-repo-%s" + name = "%s" description = "test" } resource "github_repository" "test" { - name = "tf-acc-test-%[1]s" + name = "%s" } resource "github_team_repository" "test" { @@ -115,7 +121,7 @@ func TestAccGithubTeamRepository(t *testing.T) { repository = "${github_repository.test.name}" permission = "pull" } - `, randomID) + `, teamName, repoName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_team_repository.test", "team_id"), @@ -142,16 +148,18 @@ func TestAccGithubTeamRepository(t *testing.T) { func TestAccGithubTeamRepositoryArchivedRepo(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-archive-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%srepo-team-archive-%s", testResourcePrefix, randomID) t.Run("can delete team repository access from archived repositories without error", func(t *testing.T) { config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-archive-%s" + name = "%s" description = "test team for archived repo" } resource "github_repository" "test" { - name = "tf-acc-test-team-archive-%[1]s" + name = "%s" auto_init = true } @@ -160,16 +168,16 @@ func TestAccGithubTeamRepositoryArchivedRepo(t *testing.T) { repository = github_repository.test.name permission = "pull" } - `, randomID) + `, teamName, repoName) archivedConfig := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-archive-%s" + name = "%s" description = "test team for archived repo" } resource "github_repository" "test" { - name = "tf-acc-test-team-archive-%[1]s" + name = "%s" auto_init = true archived = true } @@ -179,7 +187,7 @@ func TestAccGithubTeamRepositoryArchivedRepo(t *testing.T) { repository = github_repository.test.name permission = "pull" } - `, randomID) + `, teamName, repoName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -206,16 +214,16 @@ func TestAccGithubTeamRepositoryArchivedRepo(t *testing.T) { { Config: fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-archive-%s" + name = "%s" description = "test team for archived repo" } resource "github_repository" "test" { - name = "tf-acc-test-team-archive-%[1]s" + name = "%s" auto_init = true archived = true } - `, randomID), + `, teamName, repoName), }, }, }) diff --git a/github/resource_github_team_settings_test.go b/github/resource_github_team_settings_test.go index cb9544c481..053440a33f 100644 --- a/github/resource_github_team_settings_test.go +++ b/github/resource_github_team_settings_test.go @@ -13,16 +13,17 @@ import ( func TestAccGithubTeamSettings(t *testing.T) { t.Run("manages team settings can use team_id id and slug", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-repo-%s" + name = "%s" description = "generated by terraform provider automated testing" } resource "github_team_settings" "test" { team_id = "${github_team.test.id}" } - `, randomID) + `, teamName) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("github_team_settings.test", "team_id"), @@ -48,9 +49,10 @@ func TestAccGithubTeamSettings(t *testing.T) { t.Run("manages team code review settings", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-repo-%s" + name = "%s" description = "generated by terraform provider automated testing" } @@ -62,7 +64,7 @@ func TestAccGithubTeamSettings(t *testing.T) { notify = true } } - `, randomID) + `, teamName) checks := map[string]resource.TestCheckFunc{ "round_robin": resource.ComposeTestCheckFunc( @@ -123,9 +125,10 @@ func TestAccGithubTeamSettings(t *testing.T) { t.Run("cannot manage team code review settings if disabled", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-test-team-repo-%s" + name = "%s" description = "generated by terraform provider automated testing" } @@ -137,7 +140,7 @@ func TestAccGithubTeamSettings(t *testing.T) { notify = true } } - `, randomID) + `, teamName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, diff --git a/github/resource_github_team_sync_group_mapping_test.go b/github/resource_github_team_sync_group_mapping_test.go index e99e471ff0..6874317323 100644 --- a/github/resource_github_team_sync_group_mapping_test.go +++ b/github/resource_github_team_sync_group_mapping_test.go @@ -14,7 +14,8 @@ import ( func TestAccGithubTeamSyncGroupMapping_basic(t *testing.T) { t.Run("creates a team sync group mapping", func(t *testing.T) { - teamName := acctest.RandomWithPrefix("tf-acc-test-%s") + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-sync-%s", testResourcePrefix, randomID) rn := "github_team_sync_group_mapping.test_mapping" resource.Test(t, resource.TestCase{ @@ -45,7 +46,8 @@ func TestAccGithubTeamSyncGroupMapping_basic(t *testing.T) { }) t.Run("creates a team sync group mapping and then deletes it", func(t *testing.T) { - teamName := acctest.RandomWithPrefix("tf-acc-test-%s") + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-sync-%s", testResourcePrefix, randomID) rn := "github_team_sync_group_mapping.test_mapping" resource.Test(t, resource.TestCase{ @@ -65,7 +67,8 @@ func TestAccGithubTeamSyncGroupMapping_basic(t *testing.T) { }) t.Run("creates a team sync group mapping and then updates it", func(t *testing.T) { - teamName := acctest.RandomWithPrefix("tf-acc-test-%s") + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-sync-%s", testResourcePrefix, randomID) description := "tf-acc-group-description-update" rn := "github_team_sync_group_mapping.test_mapping" @@ -109,7 +112,8 @@ func TestAccGithubTeamSyncGroupMapping_basic(t *testing.T) { }) t.Run("creates empty team sync group mapping", func(t *testing.T) { - teamName := acctest.RandomWithPrefix("tf-acc-test-%s") + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-sync-%s", testResourcePrefix, randomID) rn := "github_team_sync_group_mapping.test_mapping" resource.Test(t, resource.TestCase{ diff --git a/github/resource_github_team_test.go b/github/resource_github_team_test.go index 19e41faaef..eb34895d32 100644 --- a/github/resource_github_team_test.go +++ b/github/resource_github_team_test.go @@ -11,11 +11,12 @@ import ( func TestAccGithubTeam(t *testing.T) { t.Run("creates a team configured with defaults", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-%s" + name = "%s" } -`, randomID) +`, teamName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -35,13 +36,14 @@ resource "github_team" "test" { t.Run("creates a team configured with alternatives", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testResourceName := fmt.Sprintf("%steam-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "test" { - name = "tf-acc-%s" + name = "%s" privacy = "closed" notification_setting = "notifications_disabled" } -`, randomID) +`, testResourceName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -61,47 +63,50 @@ resource "github_team" "test" { t.Run("creates a hierarchy of teams", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + team01Name := fmt.Sprintf("%steam-hier01-%s", testResourcePrefix, randomID) + team02Name := fmt.Sprintf("%steam-hier02-%s", testResourcePrefix, randomID) + team03Name := fmt.Sprintf("%steam-hier03-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_team" "team01" { - name = "tf-acc-team01-%s" + name = "%s" description = "Terraform acc test team01a" privacy = "closed" } resource "github_team" "team02" { - name = "tf-acc-team02-%[1]s" + name = "%s" description = "Terraform acc test team02a" privacy = "closed" parent_team_id = "${github_team.team01.id}" } resource "github_team" "team03" { - name = "tf-acc-team03-%[1]s" + name = "%s" description = "Terraform acc test team03a" privacy = "closed" parent_team_id = "${github_team.team02.slug}" } - `, randomID) + `, team01Name, team02Name, team03Name) config2 := fmt.Sprintf(` resource "github_team" "team01" { - name = "tf-acc-team01-%s" + name = "%s" description = "Terraform acc test team01b" privacy = "closed" } resource "github_team" "team02" { - name = "tf-acc-team02-%[1]s" + name = "%s" description = "Terraform acc test team02b" privacy = "closed" } resource "github_team" "team03" { - name = "tf-acc-team03-%[1]s" + name = "%s" description = "Terraform acc test team03b" privacy = "closed" } - `, randomID) + `, team01Name, team02Name, team03Name) check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("github_team.team02", "parent_team_id"), @@ -135,12 +140,13 @@ resource "github_team" "test" { t.Run("creates a team and removes the default maintainer", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + teamName := fmt.Sprintf("%steam-no-maint-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` -resource "github_team" "test" { - name = "tf-acc-%s" - create_default_maintainer = false -} -`, randomID) + resource "github_team" "test" { + name = "%s" + create_default_maintainer = false + } + `, teamName) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnlessHasOrgs(t) }, @@ -158,9 +164,8 @@ resource "github_team" "test" { t.Run("updates_slug", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - slug := fmt.Sprintf("tf-acc-%s", randomID) - slugUpdated := fmt.Sprintf("tf-acc-updated-%s", randomID) - + teamName := fmt.Sprintf("%steam-slug-%s", testResourcePrefix, randomID) + teamNameUpdated := fmt.Sprintf("%s-updated", teamName) config := ` resource "github_team" "test" { name = "%s" @@ -172,15 +177,15 @@ resource "github_team" "test" { ProviderFactories: providerFactories, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(config, slug), + Config: fmt.Sprintf(config, teamName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("github_team.test", "slug", slug), + resource.TestCheckResourceAttr("github_team.test", "slug", teamName), ), }, { - Config: fmt.Sprintf(config, slugUpdated), + Config: fmt.Sprintf(config, teamNameUpdated), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("github_team.test", "slug", slugUpdated), + resource.TestCheckResourceAttr("github_team.other", "description", teamNameUpdated), ), }, }, diff --git a/github/resource_github_user_invitation_accepter_test.go b/github/resource_github_user_invitation_accepter_test.go index 5b4772fcd6..79a8a3ae9a 100644 --- a/github/resource_github_user_invitation_accepter_test.go +++ b/github/resource_github_user_invitation_accepter_test.go @@ -21,7 +21,8 @@ func TestAccGithubUserInvitationAccepter(t *testing.T) { t.Run("accepts an invitation", func(t *testing.T) { rn := "github_repository_collaborator.test" - repoName := fmt.Sprintf("tf-acc-test-collab-%s", acctest.RandString(5)) + randomID := acctest.RandString(5) + repoName := fmt.Sprintf("%srepo-invitation-%s", testResourcePrefix, randomID) resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, diff --git a/github/resource_github_workflow_repository_permissions_test.go b/github/resource_github_workflow_repository_permissions_test.go index 4d7878d789..8e269af12b 100644 --- a/github/resource_github_workflow_repository_permissions_test.go +++ b/github/resource_github_workflow_repository_permissions_test.go @@ -12,10 +12,11 @@ func TestAccGithubWorkflowRepositoryPermissions(t *testing.T) { t.Run("test setting of basic workflow repository permissions", func(t *testing.T) { defaultWorkflowPermissions := "read" randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-workflow-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -24,7 +25,7 @@ func TestAccGithubWorkflowRepositoryPermissions(t *testing.T) { default_workflow_permissions = "%s" repository = github_repository.test.name } - `, randomID, defaultWorkflowPermissions) + `, repoName, defaultWorkflowPermissions) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -49,10 +50,11 @@ func TestAccGithubWorkflowRepositoryPermissions(t *testing.T) { canApprovePullRequestReviews := "true" randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%srepo-workflow-perms-%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { - name = "tf-acc-test-topic-%[1]s" + name = "%[1]s" description = "Terraform acceptance tests %[1]s" topics = ["terraform", "testing"] } @@ -62,7 +64,7 @@ func TestAccGithubWorkflowRepositoryPermissions(t *testing.T) { can_approve_pull_request_reviews = %s repository = github_repository.test.name } - `, randomID, defaultWorkflowPermissions, canApprovePullRequestReviews) + `, repoName, defaultWorkflowPermissions, canApprovePullRequestReviews) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(