Skip to content

Commit f4a5b1a

Browse files
authored
[MAINT]: Update GNUmakefile to enhance test command functionality (#3051)
* chore: Update GNUmakefile to enhance test command functionality - Renamed TESTARGS to COVERAGEARGS for clarity. - Added variable references and examples for test-specific variables. - Improved test and acceptance test commands to include branch information and coverage options. Signed-off-by: Timo Sand <[email protected]> * Ensure `make testacc` only ever runs `TestAcc` prefixed tests Signed-off-by: Timo Sand <[email protected]> * Move `CGO_ENABLED` as a global export Signed-off-by: Timo Sand <[email protected]> * Remove leftover inlined `CGO_ENABLED` Signed-off-by: Timo Sand <[email protected]> * Revert global `CGO_ENABLED=0` export Signed-off-by: Timo Sand <[email protected]> * Set `TEST` to package name to get real-time output for each test execution Signed-off-by: Timo Sand <[email protected]> * Use `-skip` in unit test target Signed-off-by: Timo Sand <[email protected]> * Remove unused target Signed-off-by: Timo Sand <[email protected]> --------- Signed-off-by: Timo Sand <[email protected]>
1 parent 16c1e02 commit f4a5b1a

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

GNUmakefile

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
TEST?=$$(go list ./... |grep -v 'vendor')
21
SWEEP?=repositories,teams
3-
WEBSITE_REPO=github.com/hashicorp/terraform-website
42
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
519

6-
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
727

828
default: build
929

@@ -27,19 +47,20 @@ lintcheck:
2747
golangci-lint run ./...
2848

2949
test:
30-
CGO_ENABLED=0 go test ./...
31-
# 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;
3259

3360
testacc:
34-
TF_ACC=1 CGO_ENABLED=0 go test -run "^TestAcc*" $(TEST) -v $(TESTARGS) -timeout 120m -count=1
35-
36-
test-compile:
37-
@if [ "$(TEST)" = "./..." ]; then \
38-
echo "ERROR: Set TEST to a specific package. For example,"; \
39-
echo " make test-compile TEST=./$(PKG_NAME)"; \
40-
exit 1; \
41-
fi
42-
CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS)
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
4364

4465
sweep:
4566
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
@@ -63,4 +84,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
6384
endif
6485
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
6586

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

0 commit comments

Comments
 (0)