-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathMakefile
More file actions
109 lines (95 loc) · 4.69 KB
/
Copy pathMakefile
File metadata and controls
109 lines (95 loc) · 4.69 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
#-----------------------------------------------------------------------------------------------------------------------
# Variables (https://www.gnu.org/software/make/manual/html_node/Using-Variables.html#Using-Variables)
#-----------------------------------------------------------------------------------------------------------------------
.DEFAULT_GOAL := help
GO_BIN ?= $(shell go env GOPATH)/bin
#-----------------------------------------------------------------------------------------------------------------------
# Rules (https://www.gnu.org/software/make/manual/html_node/Rule-Introduction.html#Rule-Introduction)
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: help generate
help: ## Show this help
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
#-----------------------------------------------------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: deps
deps: ## Download dependencies
@echo "==> Downloading dependencies to vendor folder..."
@go mod vendor -v
$(GO_BIN)/golangci-lint:
${call print, "Installing golangci-lint"}
@go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
$(GO_BIN)/govulncheck:
${call print, "Installing govulncheck"}
@go install -v golang.org/x/vuln/cmd/govulncheck@latest
#-----------------------------------------------------------------------------------------------------------------------
# Checks
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: lint check-vuln check-getters
lint: $(GO_BIN)/golangci-lint ## Run linting on the go files
@echo "==> Running linting on the library with golangci-lint..."
@golangci-lint run -v --fix -c .golangci.yml . ./authentication/... ./internal/...
check-vuln: $(GO_BIN)/govulncheck ## Check for vulnerabilities
@echo "==> Checking for vulnerabilities..."
@govulncheck -show verbose ./...
#-----------------------------------------------------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------------------------------------------------
.PHONY: test test-record test-e2e
WIREMOCK_COMPOSE_FILE := wiremock/docker-compose.test.yml
test: ## Run tests. To run a specific test pass the FILTER var. Usage `make test FILTER="TestResourceServer_Read"`
@WIREMOCK_STARTED_BY_MAKE=false; \
if [ -n "$$WIREMOCK_PORT" ]; then \
WIREMOCK_URL="http://localhost:$$WIREMOCK_PORT"; \
if curl -s "$$WIREMOCK_URL/__admin/mappings" > /dev/null 2>&1; then \
echo "==> WireMock is already running at $$WIREMOCK_URL"; \
else \
echo "==> WIREMOCK_PORT=$$WIREMOCK_PORT set but WireMock is not reachable"; \
exit 1; \
fi; \
else \
echo "==> Starting WireMock container..."; \
docker compose -f $(WIREMOCK_COMPOSE_FILE) up -d; \
WIREMOCK_STARTED_BY_MAKE=true; \
WIREMOCK_PORT=$$(docker compose -f $(WIREMOCK_COMPOSE_FILE) port wiremock 8080 | cut -d: -f2); \
WIREMOCK_URL="http://localhost:$$WIREMOCK_PORT"; \
echo "==> WireMock assigned port: $$WIREMOCK_PORT"; \
until curl -sf "$$WIREMOCK_URL/__admin/mappings" > /dev/null 2>&1; do \
sleep 0.2; \
done; \
echo "==> WireMock is ready at $$WIREMOCK_URL"; \
fi; \
echo "==> Running tests with http recordings..."; \
AUTH0_HTTP_RECORDINGS=on \
AUTH0_DOMAIN=go-auth0-dev.eu.auth0.com \
WIREMOCK_PORT=$$WIREMOCK_PORT \
WIREMOCK_URL=$$WIREMOCK_URL \
go test \
-run "$(FILTER)" \
-cover \
-coverpkg=./... \
-covermode=atomic \
-coverprofile=coverage.out \
./... ; \
EXIT_CODE=$$?; \
if [ "$$WIREMOCK_STARTED_BY_MAKE" = "true" ]; then \
echo "==> Stopping WireMock container..."; \
docker compose -f $(WIREMOCK_COMPOSE_FILE) down -v; \
fi; \
exit $$EXIT_CODE
test-record: ## Run authentication tests and record http interactions. To run a specific test pass the FILTER var. Usage `make test-record FILTER="TestResourceServer_Read"`
@echo "==> Running authentication tests and recording http interactions..."
@AUTH0_HTTP_RECORDINGS=on \
go test \
-run "$(FILTER)" \
./authentication/...
test-e2e: ## Run authentication tests without http recordings. To run a specific test pass the FILTER var. Usage `make test-e2e FILTER="TestResourceServer_Read"`
@echo "==> Running authentication tests against a real Auth0 tenant..."
@go test \
-run "$(FILTER)" \
-cover \
-coverpkg=./... \
-covermode=atomic \
-coverprofile=coverage.out \
-timeout 20m \
./authentication/...