Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TEST?=$$(go list ./... |grep -v 'vendor')
SWEEP?=repositories,teams
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=github

Expand Down Expand Up @@ -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..."
Expand All @@ -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
2 changes: 1 addition & 1 deletion github/acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
enterprise testMode = "enterprise"
)

const testResourcePrefix = "test-acc-"
const testResourcePrefix = "tf-acc-test-"

var (
orgTestModes = []testMode{organization, team, enterprise}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions github/data_source_github_actions_environment_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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" {
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down
5 changes: 3 additions & 2 deletions github/data_source_github_actions_public_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions github/data_source_github_actions_registration_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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" {
Expand All @@ -33,15 +34,15 @@ func TestAccGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplateDataSour

config3 := 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 = true
}
`, randomID)
`, repoName)

config4 := config3 + `
data "github_actions_repository_oidc_subject_claim_customization_template" "test" {
Expand Down
7 changes: 4 additions & 3 deletions github/data_source_github_actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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" {
Expand All @@ -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"),
Expand Down
7 changes: 4 additions & 3 deletions github/data_source_github_actions_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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" {
Expand All @@ -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"),
Expand Down
10 changes: 6 additions & 4 deletions github/data_source_github_branch_protection_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -41,18 +42,19 @@ 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
}

resource "github_branch_protection" "protection" {
repository_id = github_repository.test.name
pattern = "main*"
}
`, randomID)
`, repoName)

config2 := config + `
data "github_branch_protection_rules" "all" {
Expand Down
10 changes: 6 additions & 4 deletions github/data_source_github_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ 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
}

data "github_branch" "test" {
repository = github_repository.test.name
branch = "main"
}
`, randomID)
`, repoName)

check := resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
Expand All @@ -46,18 +47,19 @@ 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
// }

// data "github_branch" "test" {
// repository = github_repository.test.name
// branch = "xxxxxx"
// }
// `, randomID)
// `, repoName)

// check := resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr(
Expand Down
5 changes: 3 additions & 2 deletions github/data_source_github_codespaces_public_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading