File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ name: Test and coverage
33on : [push, pull_request]
44
55jobs :
6- build :
6+ unit-tests :
77 runs-on : ubuntu-latest
88 steps :
99 - uses : actions/checkout@v4.2.2
@@ -13,10 +13,49 @@ jobs:
1313 with :
1414 go-version : ' 1.25'
1515 - name : Run coverage
16- run : go env -w GOTOOLCHAIN=go1.25.0+auto && go test -coverpkg=./... ./... -race -coverprofile=coverage.out -covermode=atomic
16+ run : go env -w GOTOOLCHAIN=go1.25.0+auto && go test -coverpkg=./... ./... -race -coverprofile=coverage.out -covermode=atomic
1717 - name : Upload coverage to Codecov
1818 uses : codecov/codecov-action@v5
1919 with :
2020 verbose : true
2121 env :
2222 CODECOV_TOKEN : ${{ secrets.CODECOV_TOKEN }}
23+
24+ integration-tests :
25+ runs-on : ubuntu-latest
26+ needs : unit-tests
27+ services :
28+ vault :
29+ image : hashicorp/vault:1.18
30+ ports :
31+ - 8200:8200
32+ env :
33+ VAULT_DEV_ROOT_TOKEN_ID : root-token
34+ VAULT_DEV_LISTEN_ADDRESS : 0.0.0.0:8200
35+ VAULT_ADDR : http://127.0.0.1:8200
36+ options : >-
37+ --cap-add=IPC_LOCK
38+ --health-cmd="vault status"
39+ --health-interval=2s
40+ --health-timeout=5s
41+ --health-retries=15
42+ steps :
43+ - uses : actions/checkout@v4.2.2
44+ - uses : actions/setup-go@v5.4.0
45+ with :
46+ go-version : ' 1.25'
47+ - name : Wait for Vault to be ready
48+ run : |
49+ for i in {1..30}; do
50+ if curl -s http://127.0.0.1:8200/v1/sys/health | grep -q "initialized"; then
51+ echo "Vault is ready"
52+ break
53+ fi
54+ echo "Waiting for Vault..."
55+ sleep 1
56+ done
57+ - name : Run integration tests
58+ env :
59+ VAULT_ADDR : http://127.0.0.1:8200
60+ VAULT_TOKEN : root-token
61+ run : go env -w GOTOOLCHAIN=go1.25.0+auto && go test -tags=integration -v -race ./...
Original file line number Diff line number Diff line change 1+ .PHONY : test test-unit test-integration test-coverage lint build clean docker-up docker-down
2+
3+ # Default target
4+ all : lint test build
5+
6+ # Build the binary
7+ build :
8+ go build -o vault-audit-filter .
9+
10+ # Run unit tests
11+ test-unit :
12+ go test -v -race ./...
13+
14+ # Run integration tests (requires Vault to be running)
15+ test-integration :
16+ go test -tags=integration -v -race ./...
17+
18+ # Run all tests
19+ test : test-unit
20+
21+ # Run tests with coverage
22+ test-coverage :
23+ go test -coverpkg=./... ./... -race -coverprofile=coverage.out -covermode=atomic
24+ go tool cover -func=coverage.out
25+
26+ # Run linter
27+ lint :
28+ go vet ./...
29+ go fmt ./...
30+
31+ # Clean build artifacts
32+ clean :
33+ rm -f vault-audit-filter
34+ rm -f coverage.out
35+
36+ # Start Vault for integration tests
37+ docker-up :
38+ docker compose up -d
39+ @echo " Waiting for Vault to be ready..."
40+ @for i in $$(seq 1 30 ) ; do \
41+ if curl -s http://127.0.0.1:8200/v1/sys/health | grep -q " initialized" ; then \
42+ echo " Vault is ready" ; \
43+ break ; \
44+ fi ; \
45+ echo " Waiting..." ; \
46+ sleep 1; \
47+ done
48+
49+ # Stop Vault
50+ docker-down :
51+ docker compose down
52+
53+ # Run integration tests with docker
54+ integration : docker-up
55+ VAULT_ADDR=http://127.0.0.1:8200 VAULT_TOKEN=root-token go test -tags=integration -v -race ./...
56+ $(MAKE ) docker-down
Original file line number Diff line number Diff line change 1+ services :
2+ vault :
3+ image : hashicorp/vault:1.18
4+ container_name : vault-integration
5+ ports :
6+ - " 8200:8200"
7+ environment :
8+ VAULT_DEV_ROOT_TOKEN_ID : " root-token"
9+ VAULT_DEV_LISTEN_ADDRESS : " 0.0.0.0:8200"
10+ VAULT_ADDR : " http://127.0.0.1:8200"
11+ cap_add :
12+ - IPC_LOCK
13+ command : " vault server -dev -dev-root-token-id=root-token -dev-listen-address=0.0.0.0:8200"
14+ healthcheck :
15+ test : ["CMD", "vault", "status"]
16+ interval : 2s
17+ timeout : 5s
18+ retries : 10
19+
20+ # UDP receiver for testing forwarding
21+ udp-receiver :
22+ image : alpine:3.19
23+ container_name : udp-receiver-integration
24+ ports :
25+ - " 9999:9999/udp"
26+ command : ["nc", "-luk", "-p", "9999"]
You can’t perform that action at this time.
0 commit comments