-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
140 lines (106 loc) · 4.35 KB
/
Makefile
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
SHELL=/usr/bin/env bash
UNIT_TEST_TAGS=
BUILD_TAGS=-tags "example,mocks,codegen,integration,slow"
CI_TAGS="example,mocks,codegen,integration"
GOTESTSUM_FMT="github-actions"
#GOTESTSUM_FMT="standard-verbose"
#GOTESTSUM_FMT="pkgname-and-test-fails"
#GOTESTSUM_FMT="testname"
SDK_PKGS=./pkg/...
RUN_NONE=-run NOTHING
RUN_INTEG=-run '^Test_Integration_'
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show the help menu
@echo "Usage: make <target>"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: all deps mocks mocks-build-tag vet lint lint-ci lint-local unit
all: unit ## Run all the checks and tests
@echo "All checks and tests"
deps: ## Install development dependencies
@echo "Installing dependencies"
@go mod download -x all
@go install gotest.tools/gotestsum@latest
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@go install github.com/vektra/mockery/[email protected]
@#go get github.com/stretchr/testify/[email protected]
mocks: ## Generate mocks
@echo "Generating mocks"
@mockery
@#$(MAKE) mocks-build-tag
mocks-build-tag:
@echo "Adding mocks build tag to mock files"
@if [ "$$(uname)" = "Darwin" ]; then \
find ./mocks/ -name '*_mock.go' -exec gsed -i '/^package/ i //go:build mocks\n' {} +; \
else \
find ./mocks/ -name '*_mock.go' -exec sed -i '/^package/ i //go:build mocks\n' {} +; \
fi
lint: mocks vet lint-ci ## Generate mocks and run all linters
lint-ci:
@echo "Running golangci-lint"
@golangci-lint run --build-tags=${CI_TAGS} --out-format=colored-line-number ./...
lint-local:
@echo "Running golangci-lint locally"
@which golangci-lint
@golangci-lint --version
@golangci-lint run --build-tags=${CI_TAGS} ./...
.PHONY: examples lint-examples run-examples
examples: lint-examples run-examples ## Lint and run all examples
lint-examples:
@for dir in $(shell find ./example -type d -mindepth 1 -maxdepth 1); do \
echo "Running golangci-lint in: $$dir"; \
(cd $$dir && go get && go mod tidy && golangci-lint run ./...) || exit $$?; \
done
run-examples:
@for dir in $(shell find ./example -type d -mindepth 1 -maxdepth 1); do \
echo "Running example: $$dir"; \
(cd $$dir && go get && go mod tidy && go run ./...) || exit $$?; \
echo "Done"; \
echo "================"; \
done
vet: ## Run go vet
@go vet ${BUILD_TAGS} --all ${SDK_PKGS}
##
# Unit tests
##
.PHONY: unit-race unit-pkg
unit: lint unit-pkg ## Run all unit tests
unit-pkg:
@gotestsum -f ${GOTESTSUM_FMT} -- -timeout=4m ${BUILD_TAGS} ${SDK_PKGS}
unit-race:
@gotestsum -f ${GOTESTSUM_FMT} -- -timeout=6m -cpu=4 -race -count=1 ${BUILD_TAGS} ${SDK_PKGS}
##
# Integration tests
##
.PHONY: e2e e2e-deps e2e-test e2e-test-cli e2e-test-short e2e-test-full e2e-test-slow
e2e: lint e2e-deps e2e-test-cli e2e-test-short
e2e-test: e2e-test-cli e2e-test-short ## Run e2e short integration tests
e2e-deps: ## Install e2e dependencies
@echo "Installing e2e dependencies"
@pip install aws-encryption-sdk-cli
@aws-encryption-cli --version
@aws --version
e2e-test-cli:
@echo "Running e2e CLI test"
@gotestsum -f ${GOTESTSUM_FMT} -- -timeout=1m -tags "integration" -run '^Test_Cli_Integration' ./test/e2e/...
e2e-test-short:
@echo "Running e2e short tests"
@gotestsum -f ${GOTESTSUM_FMT} -- -short -timeout=10m -tags "integration" ${RUN_INTEG} ./test/e2e/...
e2e-test-full: ## Run all e2e integration tests
@echo "Running full e2e tests, it will take a while"
@gotestsum -f ${GOTESTSUM_FMT} -- -timeout=15m -tags "integration" ${RUN_INTEG} ./test/e2e/...
e2e-test-slow: ## Run all slow e2e integration tests
@echo "Running very slow e2e tests"
@gotestsum -f testname -- -timeout=30m -tags "integration,slow" ${RUN_INTEG} ./test/e2e/...
##
# Coverage
##
.PHONY: test-cover cover-html
test-cover: ## Run tests with coverage
@#CGO_ENABLED=1 go test -count=1 -coverpkg=./... -covermode=atomic -coverprofile coverage.out ./...
@CGO_ENABLED=1 go test -timeout=10m -tags example,mocks,codegen,integration -cpu=2 -count=1 -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./pkg/...
@#CGO_ENABLED=1 go test -tags ${CI_TAGS} -count=1 -coverpkg=./... -covermode=atomic -coverprofile coverage.out ./pkg/...
@grep -v -E -f .covignore coverage.out > coverage.filtered.out
@mv coverage.filtered.out coverage.out
cover-html: ## Convert coverage to HTML report
@go tool cover -html=coverage.out -o coverage.html