Skip to content

Commit 9978a3d

Browse files
authored
Merge branch 'main' into feature/copilot-code-review-ruleset
2 parents 89460b9 + f4a5b1a commit 9978a3d

107 files changed

Lines changed: 1511 additions & 1087 deletions

File tree

Some content is hidden

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

GNUmakefile

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1-
TEST?=$$(go list ./... |grep -v 'vendor')
2-
WEBSITE_REPO=github.com/hashicorp/terraform-website
1+
SWEEP?=repositories,teams
32
PKG_NAME=github
3+
TEST?=./$(PKG_NAME)/...
4+
WEBSITE_REPO=github.com/hashicorp/terraform-website
5+
6+
COVERAGEARGS?=-race -coverprofile=coverage.txt -covermode=atomic
7+
8+
# VARIABLE REFERENCE:
9+
#
10+
# Test-specific variables:
11+
# T=<pattern> - Test name pattern (e.g., TestAccGithubRepository)
12+
# COV=true - Enable coverage
13+
#
14+
#
15+
# Examples:
16+
# make test T=TestMigrate # Run only schema migration unit tests
17+
# make test COV=true # Run all unit tests with coverage
18+
# make testacc T=TestAccGithubRepositories\$$ COV=true # Run only acceptance tests for a specific Test name with coverage
419

5-
export TESTARGS=-race -coverprofile=coverage.txt -covermode=atomic
20+
ifneq ($(origin T), undefined)
21+
RUNARGS = -run='$(T)'
22+
endif
23+
24+
ifneq ($(origin COV), undefined)
25+
RUNARGS += $(COVERAGEARGS)
26+
endif
627

728
default: build
829

@@ -26,19 +47,24 @@ lintcheck:
2647
golangci-lint run ./...
2748

2849
test:
29-
CGO_ENABLED=0 go test ./...
30-
# commenting this out for release tooling, please run testacc instead
50+
@branch=$$(git rev-parse --abbrev-ref HEAD); \
51+
printf "==> Running unit tests on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
52+
CGO_ENABLED=0 go test $(TEST) \
53+
-timeout=30s \
54+
-parallel=4 \
55+
-v \
56+
-skip '^TestAcc' \
57+
$(RUNARGS) $(TESTARGS) \
58+
-count 1;
3159

3260
testacc:
33-
TF_ACC=1 CGO_ENABLED=0 go test -run "^TestAcc*" $(TEST) -v $(TESTARGS) -timeout 120m -count=1
61+
@branch=$$(git rev-parse --abbrev-ref HEAD); \
62+
printf "==> Running acceptance tests on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
63+
TF_ACC=1 CGO_ENABLED=0 go test $(TEST) -v -run '^TestAcc' $(RUNARGS) $(TESTARGS) -timeout 120m -count=1
3464

35-
test-compile:
36-
@if [ "$(TEST)" = "./..." ]; then \
37-
echo "ERROR: Set TEST to a specific package. For example,"; \
38-
echo " make test-compile TEST=./$(PKG_NAME)"; \
39-
exit 1; \
40-
fi
41-
CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS)
65+
sweep:
66+
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
67+
go test $(TEST) -v -sweep=$(SWEEP) $(SWEEPARGS)
4268

4369
website:
4470
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
@@ -58,4 +84,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
5884
endif
5985
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
6086

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

github/acc_test.go

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

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

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

github/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var (
5959
func RateLimitedHTTPClient(client *http.Client, writeDelay, readDelay, retryDelay time.Duration, parallelRequests bool, retryableErrors map[int]bool, maxRetries int) *http.Client {
6060
client.Transport = NewEtagTransport(client.Transport)
6161
client.Transport = NewRateLimitTransport(client.Transport, WithWriteDelay(writeDelay), WithReadDelay(readDelay), WithParallelRequests(parallelRequests))
62-
client.Transport = logging.NewSubsystemLoggingHTTPTransport("GitHub", client.Transport)
62+
client.Transport = logging.NewLoggingHTTPTransport(client.Transport)
6363
client.Transport = newPreviewHeaderInjectorTransport(map[string]string{
6464
// TODO: remove when Stone Crop preview is moved to general availability in the GraphQL API
6565
"Accept": "application/vnd.github.stone-crop-preview+json",

github/data_source_github_actions_environment_public_key_test.go

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

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

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

github/data_source_github_actions_environment_secrets_test.go

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

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

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

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

github/data_source_github_actions_environment_variables_test.go

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

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

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

github/data_source_github_actions_organization_secrets_test.go

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

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

github/data_source_github_actions_public_key_test.go

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

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

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

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

github/data_source_github_actions_registration_token_test.go

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

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

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

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

github/data_source_github_actions_repository_oidc_subject_claim_customization_template_test.go

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

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

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

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

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

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

0 commit comments

Comments
 (0)