-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (151 loc) · 8.44 KB
/
Copy pathMakefile
File metadata and controls
171 lines (151 loc) · 8.44 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
# init-hooks sets up git to recognise the .githooks directory as the hooks path for this repo
# it also makes all scripts in the .githooks folder executable
init-hooks:
git config core.hooksPath .githooks
chmod +x .githooks/*
mockgen:
go generate ./...
setup: init-hooks
ui_install:
scripts/ui.sh -b $(type)
build:
scripts/build.sh
.PHONY: ui-build ui-build-fresh
ui-build:
scripts/build-ui.sh
ui-build-fresh:
INSTALL_DEPS=1 scripts/build-ui.sh
.PHONY: test
test:
@go test -race -p 1 $(shell go list ./... | grep -v '/e2e') -v -timeout 30m
# Get Docker socket from active context if DOCKER_HOST is not set
DOCKER_HOST_VAL := $(or $(DOCKER_HOST),$(shell docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null || echo ""))
DOCKER_CONTEXT := $(shell docker context show 2>/dev/null || echo "default")
DOCKER_SOCKET_PATH := $(shell echo "$(DOCKER_HOST_VAL)" | sed 's|^unix://||')
# The JWT secrets mirror the e2e workflows. Without them config.LoadConfig
# fails inside setup and every test in the package reports a setup error.
TEST_ENV := DOCKER_HOST="$(DOCKER_HOST_VAL)" TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE="$(DOCKER_SOCKET_PATH)" \
CONVOY_JWT_SECRET="$(or $(CONVOY_JWT_SECRET),test-access-secret)" \
CONVOY_JWT_REFRESH_SECRET="$(or $(CONVOY_JWT_REFRESH_SECRET),test-refresh-secret)"
# Fast E2E tests - Run on PRs (10-15 minutes)
.PHONY: test_e2e_fast
test_e2e_fast:
@echo "Using docker context: $(DOCKER_CONTEXT) (DOCKER_HOST=$(DOCKER_HOST_VAL))"
@echo "Running Fast E2E tests (non-pubsub)..."
@echo "Running Direct Event tests..."
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_DirectEvent_AllSubscriptions
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_DirectEvent_MustMatchSubscription
@echo "Running Fanout Event tests..."
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_FanOutEvent_AllSubscriptions
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_FanOutEvent_MustMatchSubscription
@echo "Running Form Endpoint tests..."
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_FormEndpoint_ContentType
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_FormEndpoint_WithCustomHeaders
@echo "Running OAuth2 tests..."
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_OAuth2_SharedSecret
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_OAuth2_ClientAssertion
@echo "Running Job ID tests..."
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_SingleEvent_JobID_Format
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_SingleEvent_JobID_Deduplication
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_FanoutEvent_JobID_Format
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_FanoutEvent_MultipleOwners
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BroadcastEvent_JobID_Format
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BroadcastEvent_AllSubscribers
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_DynamicEvent_JobID_Format
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_DynamicEvent_MultipleEventTypes
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_ReplayEvent_JobID_Format
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_ReplayEvent_MultipleReplays
@echo "Running Bulk Onboard tests..."
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_JSON_CreatesEndpointsAndSubscriptions
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_CSV_CreatesEndpointsAndSubscriptions
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_DryRun_DoesNotCreateResources
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_DryRun_ReturnsValidationErrors
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_ValidationFailure_Returns400
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_EmptyItems_Returns400
@$(TEST_ENV) go test -race -v ./e2e -run TestE2E_BulkOnboard_MultipleBatches
@echo "Running Backup tests..."
@$(TEST_ENV) go test -race -v ./e2e/backup -timeout 15m
@$(MAKE) test_e2e_admin
@echo "✅ Fast E2E tests passed!"
# Admin-surface E2E tests: dashboard rollup reads, the Postgres queue provider,
# licensed event search and the Prometheus scrape. Each drives a real server
# (and worker where the path needs one) over HTTP.
.PHONY: test_e2e_admin
test_e2e_admin:
@echo "Using docker context: $(DOCKER_CONTEXT) (DOCKER_HOST=$(DOCKER_HOST_VAL))"
@echo "Running daily counts rollup tests..."
@$(TEST_ENV) go test -race -v ./e2e -run 'TestE2E_DailyCounts' -timeout 15m
@echo "Running Postgres queue provider tests..."
@$(TEST_ENV) go test -race -v ./e2e -run 'TestE2E_PostgresQueue' -timeout 15m
@echo "Running event search tests..."
@$(TEST_ENV) go test -race -v ./e2e -run 'TestE2E_EventSearch' -timeout 15m
@echo "Running Prometheus metrics tests..."
@$(TEST_ENV) go test -race -v ./e2e -run 'TestE2E_Metrics' -timeout 15m
@echo "✅ Admin E2E tests passed!"
# Index rebuilds run real CONCURRENTLY builds behind an instance-wide slot, so
# they are minutes each and belong on a schedule rather than every PR.
.PHONY: test_e2e_admin_slow
test_e2e_admin_slow:
@echo "Using docker context: $(DOCKER_CONTEXT) (DOCKER_HOST=$(DOCKER_HOST_VAL))"
@$(TEST_ENV) go test -race -v ./e2e -run 'TestE2E_IndexRebuild' -timeout 30m
@echo "✅ Slow admin E2E tests passed!"
# Slow PubSub/Message Broker tests - Run daily (60+ minutes)
.PHONY: test_e2e_pubsub
test_e2e_pubsub:
@echo "Using docker context: $(DOCKER_CONTEXT) (DOCKER_HOST=$(DOCKER_HOST_VAL))"
@echo "Running PubSub/Message Broker E2E tests..."
@echo "Running AMQP PubSub tests..."
@$(TEST_ENV) go test -race -v ./e2e/amqp -timeout 30m
@echo "Running SQS PubSub tests..."
@$(TEST_ENV) go test -race -v ./e2e/sqs -timeout 30m
@echo "Running Kafka PubSub tests..."
@$(TEST_ENV) go test -race -v ./e2e/kafka -timeout 30m
@echo "Running Google Pub/Sub tests..."
@$(TEST_ENV) go test -race -v ./e2e/pubsub -timeout 30m
@echo "✅ All PubSub E2E tests passed!"
# Original test_e2e - runs ALL tests (for local comprehensive testing)
.PHONY: test_e2e
test_e2e: test_e2e_fast test_e2e_pubsub
@echo "✅ All E2E tests (fast + pubsub) passed!"
# Run all E2E tests together (may be flaky, use test_e2e for CI)
test_e2e_all:
@echo "Using docker context: $(DOCKER_CONTEXT) (DOCKER_HOST=$(DOCKER_HOST_VAL))"
@$(TEST_ENV) go test -race -v ./e2e/...
# Run a specific E2E test
# Usage: make test_e2e_single TEST=TestE2E_DirectEvent_AllSubscriptions
test_e2e_single:
@echo "Using docker context: $(DOCKER_CONTEXT) (DOCKER_HOST=$(DOCKER_HOST_VAL))"
@$(TEST_ENV) go test -race -v ./e2e/... -run '$(TEST)'
generate_migration_time:
@date +"%Y%m%d%H%M%S"
migrate_create:
@go run cmd/main.go migrate create
generate_docs:
@echo "Checking required tools (run 'mise install' to install all)..."
@for tool in swag jq yq api-spec-converter openapi; do \
command -v "$$tool" >/dev/null 2>&1 || { echo "❌ $$tool not found. Run 'mise install' to install all required tools."; exit 1; }; \
done
@echo "Generating docs..."
go run docs/annotate_dtos/main.go
swag init --generatedTime --parseDependency --parseDependencyLevel 3 --parseInternal -g handlers/main.go -d api/ api/*
swag fmt -d ./api
bash docs/fix_openapi_spec.sh
api-spec-converter --from=swagger_2 --to=openapi_3 -s yaml ./docs/swagger.yaml > ./docs/v3/openapi3.yaml
api-spec-converter --from=swagger_2 --to=openapi_3 ./docs/swagger.json > ./docs/v3/openapi3.json
yq -i '.servers[0].description = "US Region" | .servers += [{"url": "https://eu.getconvoy.cloud/api", "description": "EU Region"}]' ./docs/v3/openapi3.yaml
jq '.servers[0].description = "US Region" | .servers += [{"url": "https://eu.getconvoy.cloud/api", "description": "EU Region"}]' ./docs/v3/openapi3.json > ./docs/v3/openapi3.json.tmp && mv ./docs/v3/openapi3.json.tmp ./docs/v3/openapi3.json
# Swagger 2.0 cannot express http bearer auth; upgrade the converted scheme so
# generated SDK clients add the "Bearer " prefix instead of every caller.
yq -i '.components.securitySchemes.ApiKeyAuth = {"type": "http", "scheme": "bearer"}' ./docs/v3/openapi3.yaml
jq '.components.securitySchemes.ApiKeyAuth = {"type": "http", "scheme": "bearer"}' ./docs/v3/openapi3.json > ./docs/v3/openapi3.json.tmp && mv ./docs/v3/openapi3.json.tmp ./docs/v3/openapi3.json
@echo "Validating specs..."
openapi swagger validate ./docs/swagger.json
openapi swagger validate ./docs/swagger.yaml
openapi spec validate ./docs/v3/openapi3.yaml
.PHONY: docs-generated
docs-generated:
@mkdir -p docs/generated
go run ./scripts/docs/genconfigref -output docs/generated/config-reference.json
go run ./scripts/docs/gencliref -output docs/generated/cli-reference.json
run_dependencies:
docker compose -f docker-compose.dep.yml up -d