-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathGNUmakefile
More file actions
194 lines (171 loc) · 7.75 KB
/
GNUmakefile
File metadata and controls
194 lines (171 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
TEST?=$$(go list ./... |grep -v 'vendor' |grep -v 'utils')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
PKG_NAME=nutanix
WEBSITE_REPO=github.com/hashicorp/terraform-website
default: build
build: fmtcheck
go install
test: fmtcheck
go test --tags=unit $(TEST) -timeout=30s -parallel=4
testacc: fmtcheck
@echo "==> Running testcases..."
@echo "TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 500m -coverprofile c.out -covermode=count"
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 500m -coverprofile c.out -covermode=count
# Acceptance tests with .env loaded (same as /ok-to-test). Loads .env from repo root before running.
# Output to ACC_TEST_LOG only; summary appended at end. Matches workflow logic from acceptance-test.yml.
# Usage:
# make acc-test networkingv2 # all tests in package networkingv2 (auto-detected)
# make acc-test networkingv2 TestAccV2NutanixSubnetResource_Basic # single test in specific package
# make acc-test p=networkingv2 # all tests in package (explicit)
# make acc-test p=networkingv2 TestAccV2NutanixSubnetResource_Basic # single test in specific package (explicit)
# make acc-test networkingv2 TestAccV2NutanixSubnetResource_Basic o=test_logs_nf.log
# make acc-test networkingv2 TestAccV2NutanixSubnetResource_Basic -- -o test_logs_nf.log
# make acc-test v4 # all TestAccV2Nutanix* tests
# make acc-test v3 # all TestAccNutanix* tests
# make acc-test TestAccV2NutanixSubnetResource_Basic # single test (searches all packages)
# make acc-test TestAccV2NutanixSubnet TestAccV2NutanixVpc # multiple tests (combined with |)
# Note: Don't use -p flag (it's a Make built-in). Use p= or just the package name directly.
_acc_goals := $(filter-out acc-test,$(MAKECMDGOALS))
_acc_single := $(if $(filter 1,$(words $(_acc_goals))),$(firstword $(_acc_goals)),)
ACC_TEST_LOG ?= $(if $(o),$(o),$(if $(_acc_single),test_output_$(_acc_single).log,test_output.log))
acc-test:
@bash -c '\
logfile="$(ACC_TEST_LOG)"; \
args="$(filter-out acc-test,$(MAKECMDGOALS))"; \
package_path="./..."; \
run_flag=""; \
expect_log_arg=0; \
[ -f .env ] && set -a && . ./.env && set +a; \
export TF_ACC=1 GOTRACEBACK=all GOFLAGS="-mod=mod"; \
if [ -n "$(p)" ]; then \
package_path="./nutanix/services/$(p)"; \
fi; \
for arg in $$args; do \
if [ "$$expect_log_arg" = "1" ]; then \
logfile="$$arg"; \
expect_log_arg=0; \
continue; \
fi; \
case "$$arg" in \
--) continue ;; \
-o|--output) expect_log_arg=1; continue ;; \
-o=*|--output=*) logfile="$${arg#*=}"; continue ;; \
esac; \
if [ -d "nutanix/services/$$arg" ]; then \
package_path="./nutanix/services/$$arg"; \
continue; \
fi; \
case "$$arg" in \
foundation) pattern="TestAccFoundation*" ;; \
foundation_central) pattern="TestAccFC*" ;; \
karbon) pattern="TestAccKarbon*" ;; \
v3) pattern="TestAccNutanix*" ;; \
v4) pattern="TestAccV2Nutanix*" ;; \
lcm) pattern="TestAccV2NutanixLcm*" ;; \
era) pattern="TestAccEra*" ;; \
fmt|fmtcheck|lint|tools|build|test) continue ;; \
*) pattern="$$arg" ;; \
esac; \
if [ -n "$$run_flag" ]; then \
run_flag="$$run_flag|$$pattern"; \
else \
run_flag="$$pattern"; \
fi; \
done; \
if [ "$$expect_log_arg" = "1" ]; then \
echo "acc-test: missing file name after -o/--output" >&2; \
exit 1; \
fi; \
: > "$$logfile"; \
echo "==> Loading .env and running acceptance tests (output to $$logfile only; summary at end)..." >> "$$logfile"; \
if [ -n "$(p)" ]; then \
echo "📦 Running tests only in package: $$package_path" >> "$$logfile"; \
elif [ "$$package_path" != "./..." ]; then \
echo "📦 Running tests only in package: $$package_path (auto-detected)" >> "$$logfile"; \
fi; \
if [ "$$package_path" != "./..." ] && [ -z "$$run_flag" ]; then \
test_args="-run=."; \
elif [ -n "$$run_flag" ]; then \
test_args="-run=$$run_flag"; \
else \
test_args="-run=."; \
fi; \
echo "==> TESTARGS = $$test_args" >> "$$logfile"; \
echo "==> Package path = $$package_path" >> "$$logfile"; \
go test "$$package_path" -v $$test_args -timeout 500m -count=1 -mod=mod 2>&1 | while IFS= read -r line; do echo "$$line" >> "$$logfile"; done; \
if [ -f "$$logfile" ] && grep -qE "^--- (PASS|FAIL|SKIP):" "$$logfile" 2>/dev/null; then \
"$(CURDIR)/scripts/acc-test-summary.sh" "$$logfile"; \
fi; \
echo "==> Log file: $$logfile"'
# Format and check targets: defined before the % pattern so "make fmt" runs only fmt, not acc-test.
fmt:
@echo "==> Fixing source code with gofmt..."
goimports -w ./$(PKG_NAME)
goimports -w ./client
goimports -w ./utils
fmtcheck:
@echo "Running fmtcheck"
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
@echo "fmtcheck done"
errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"
lint: fmtcheck
@echo "==> Checking source code against linters..."
@GOGC=30 golangci-lint cache clean
@GOGC=30 golangci-lint run --timeout=30m
tools:
@echo "make: Installing tools..."
# GO111MODULE=on go install github.com/YakDriver/tfproviderdocs
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell@latest
GO111MODULE=on go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
GO111MODULE=on go install github.com/hashicorp/copywrite@latest
GO111MODULE=on go install github.com/hashicorp/go-changelog/cmd/changelog-build@latest
GO111MODULE=on go install github.com/katbyte/terrafmt@latest
GO111MODULE=on go install github.com/pavius/impi/cmd/impi@latest
GO111MODULE=on go install github.com/rhysd/actionlint/cmd/actionlint@latest
GO111MODULE=on go install github.com/terraform-linters/tflint@latest
GO111MODULE=on go install golang.org/x/tools/cmd/stringer@latest
GO111MODULE=on go install mvdan.cc/gofumpt@latest
# GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
# GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
# GO111MODULE=on go install github.com/mitchellh/gox
vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)
# test:
# TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -coverprofile c.out
# go tool cover -html=c.out
cibuild: tools
rm -rf pkg/
gox -output "pkg/{{.OS}}_{{.Arch}}/terraform-provider-nutanix"
citest:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -coverprofile c.out
website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
website-lint:
@echo "==> Checking website against linters..."
@misspell -error -source=text website/
website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
.NOTPARALLEL:
.PHONY: default build test testacc acc-test fmt fmtcheck errcheck lint tools vet test-compile cibuild citest website website-lint website-test