forked from SAP/astonish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.integration
More file actions
162 lines (145 loc) · 7.01 KB
/
Copy pathMakefile.integration
File metadata and controls
162 lines (145 loc) · 7.01 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
# Makefile.integration — Integration and smoke tests for the sandbox layer-chain pipeline.
#
# These tests require external dependencies (Postgres, K8s cluster, auth tokens)
# and are NOT run as part of `make test` or `go test ./...`.
#
# Quick reference:
# make -f Makefile.integration test-integration # Real PG, 4 scenarios
# make -f Makefile.integration smoke # Self-driving cluster test
# make -f Makefile.integration get-token # Obtain a token via browser auth
# make -f Makefile.integration all # Both
#
# Configuration:
# Copy .env.integration.example → .env.integration and fill in your values.
# The Makefile auto-loads .env.integration if present.
#
# Prerequisites:
# test-integration:
# - ASTONISH_TEST_DSN pointing to a Postgres instance
# Example: postgres://postgres:554252@192.168.1.196:5432/astonish_dxmtlc_platform
# - Tests create/drop temporary schemas — safe for shared dev DBs
#
# smoke:
# - kubectl configured with cluster access
# - ASTONISH_TEST_TOKEN set to a valid Bearer JWT
# - ASTONISH_API_URL (default: https://devastonish.local.muxpie.com)
# - ASTONISH_SANDBOX_NS (default: astonish-sandbox)
#
# Token generation (for ASTONISH_TEST_TOKEN):
# Option A (recommended): Use the built-in command — opens a browser, outputs token:
# astonish platform issue-token --server $ASTONISH_API_URL
#
# Option B: Use the login API:
# curl -s -X POST $ASTONISH_API_URL/api/auth/login \
# -H 'Content-Type: application/json' \
# -d '{"email":"your@email.com","password":"..."}' | jq -r '.access_token'
#
# ---------------------------------------------------------------------------
# Auto-load .env.integration if it exists (does not override env vars already set).
-include .env.integration
export
.DEFAULT_GOAL := help
.PHONY: help all test-integration smoke smoke-quick clean-schemas get-token
help:
@echo "Usage: make -f Makefile.integration <target>"
@echo ""
@echo "Targets:"
@echo " test-integration Run Go integration tests against real Postgres (4 scenarios)"
@echo " smoke Full E2E smoke test (bootstraps fresh instance, 4 scenarios)"
@echo " smoke-quick Quick smoke (bash, validates current cluster state, needs token)"
@echo " get-token Obtain an access token via browser auth"
@echo " all Run both integration + smoke"
@echo " clean-schemas Drop any leftover test schemas from the DB"
@echo ""
@echo "Required environment variables:"
@echo " ASTONISH_TEST_DSN Postgres connection string (for test-integration and smoke)"
@echo ""
@echo "Optional (for smoke-quick only):"
@echo " ASTONISH_TEST_TOKEN Bearer JWT token"
@echo " ASTONISH_API_URL API base URL (default: https://devastonish.local.muxpie.com)"
@echo " ASTONISH_SANDBOX_NS K8s namespace for sandbox pods (default: astonish-sandbox)"
@echo " ASTONISH_TEST_TEAM Team slug to test (default: general)"
# ---------------------------------------------------------------------------
# Integration tests (real Postgres, isolated schemas)
# ---------------------------------------------------------------------------
test-integration:
@if [ -z "$$ASTONISH_TEST_DSN" ]; then \
echo ""; \
echo "ERROR: ASTONISH_TEST_DSN is not set."; \
echo ""; \
echo "Set it to a Postgres connection string, e.g.:"; \
echo " export ASTONISH_TEST_DSN='postgres://postgres:554252@192.168.1.196:5432/astonish_dxmtlc_platform'"; \
echo ""; \
exit 1; \
fi
@echo "═══════════════════════════════════════════════════"
@echo " Integration Tests — Layer-Chain Pipeline"
@echo " DB: $$ASTONISH_TEST_DSN"
@echo "═══════════════════════════════════════════════════"
@echo ""
go test -tags=integration -count=1 -v ./pkg/api/ -run 'TestChainScenario'
@echo ""
@echo "✓ All integration tests passed."
# ---------------------------------------------------------------------------
# Cluster E2E test (self-driving: bootstraps fresh instance, all 4 scenarios)
# ---------------------------------------------------------------------------
smoke:
@if [ -z "$$ASTONISH_TEST_DSN" ]; then \
echo ""; \
echo "ERROR: ASTONISH_TEST_DSN is not set."; \
echo ""; \
echo "Set it to a Postgres admin connection string, e.g.:"; \
echo " export ASTONISH_TEST_DSN='postgres://postgres:554252@192.168.1.196:5432/postgres'"; \
echo ""; \
exit 1; \
fi
@echo "═══════════════════════════════════════════════════"
@echo " E2E Test — Sandbox Layer-Chain Pipeline (4 scenarios)"
@echo " DB: $$ASTONISH_TEST_DSN"
@echo "═══════════════════════════════════════════════════"
@echo ""
go test -tags=e2e -count=1 -v -timeout=10m ./tests/e2e/sandbox_layerchain/ -run 'TestE2E_SandboxLayerChain'
@echo ""
@echo "✓ All layer-chain scenarios passed."
# ---------------------------------------------------------------------------
# Quick smoke (bash script — validates current cluster state, needs token)
# ---------------------------------------------------------------------------
smoke-quick:
@if [ -z "$$ASTONISH_TEST_TOKEN" ]; then \
echo ""; \
echo "ERROR: ASTONISH_TEST_TOKEN is not set."; \
echo ""; \
echo "Obtain a token with:"; \
echo " export ASTONISH_TEST_TOKEN=\$$(make -f Makefile.integration get-token)"; \
echo ""; \
exit 1; \
fi
@./scripts/smoke-layer-chain.sh
# ---------------------------------------------------------------------------
# Token helper — obtains a fresh token via browser-based auth
# ---------------------------------------------------------------------------
ASTONISH_API_URL ?= http://localhost:9393
get-token:
@echo "Obtaining access token from $$ASTONISH_API_URL..." >&2
@TOKEN=$$(go run . platform issue-token --server "$$ASTONISH_API_URL") && \
echo "$$TOKEN" && \
echo "" >&2 && \
echo "Token obtained. Export it with:" >&2 && \
echo " export ASTONISH_TEST_TOKEN='$$TOKEN'" >&2
# ---------------------------------------------------------------------------
# Run everything
# ---------------------------------------------------------------------------
all: test-integration smoke
# ---------------------------------------------------------------------------
# Utility: clean leftover test schemas (if tests crashed without cleanup)
# ---------------------------------------------------------------------------
clean-schemas:
@if [ -z "$$ASTONISH_TEST_DSN" ]; then \
echo "ERROR: ASTONISH_TEST_DSN is not set."; \
exit 1; \
fi
@echo "Dropping leftover chain_test_* schemas..."
@psql "$$ASTONISH_TEST_DSN" -t -c \
"SELECT 'DROP SCHEMA ' || schema_name || ' CASCADE;' FROM information_schema.schemata WHERE schema_name LIKE 'chain_test_%';" \
| psql "$$ASTONISH_TEST_DSN"
@echo "Done."