forked from rbaliyan/ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
160 lines (135 loc) · 4.26 KB
/
justfile
File metadata and controls
160 lines (135 loc) · 4.26 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
# Container runtime: docker or podman
DOCKER := env("DOCKER", "docker")
# MongoDB container settings
MONGO_CONTAINER := "ledger-mongo-test"
MONGO_PORT := "27020"
MONGO_IMAGE := "mongo:7.0"
# PostgreSQL container settings
PG_CONTAINER := "ledger-postgres-test"
PG_PORT := "5434"
PG_IMAGE := "postgres:16"
PG_USER := "ledger_test"
PG_PASS := "ledger_test"
PG_DB := "ledger_test"
# Default recipe
default:
@just --list
# Build all packages
build:
go build ./...
# Run tests
test:
go test ./...
# Run tests with verbose output
test-v:
go test -v ./...
# Run tests with race detector
test-race:
go test -race ./...
# Run tests with coverage
test-cover:
go test -cover ./...
# Run all integration tests (MongoDB + PostgreSQL + SQLite)
test-integration: mongo-start pg-start
#!/usr/bin/env bash
set -euo pipefail
echo "Running integration tests..."
MONGO_URI="mongodb://localhost:{{MONGO_PORT}}/?directConnection=true" \
POSTGRES_DSN="postgres://{{PG_USER}}:{{PG_PASS}}@localhost:{{PG_PORT}}/{{PG_DB}}?sslmode=disable" \
go test -v -race -count=1 ./...
just mongo-stop
just pg-stop
# Run MongoDB integration tests only
test-mongo: mongo-start
#!/usr/bin/env bash
set -euo pipefail
MONGO_URI="mongodb://localhost:{{MONGO_PORT}}/?directConnection=true" go test -v -count=1 ./mongodb/...
just mongo-stop
# Run PostgreSQL integration tests only
test-pg: pg-start
#!/usr/bin/env bash
set -euo pipefail
POSTGRES_DSN="postgres://{{PG_USER}}:{{PG_PASS}}@localhost:{{PG_PORT}}/{{PG_DB}}?sslmode=disable" go test -v -count=1 ./postgres/...
just pg-stop
# Run SQLite tests (no external services needed)
test-sqlite:
go test -v -count=1 ./sqlite/...
# Start MongoDB for testing
mongo-start:
#!/usr/bin/env bash
set -euo pipefail
if {{DOCKER}} ps -a --format '{{"{{.Names}}"}}' | grep -q "^{{MONGO_CONTAINER}}$"; then
echo "Removing existing container {{MONGO_CONTAINER}}..."
{{DOCKER}} rm -f {{MONGO_CONTAINER}} > /dev/null
fi
echo "Starting MongoDB on port {{MONGO_PORT}}..."
{{DOCKER}} run -d --name {{MONGO_CONTAINER}} -p {{MONGO_PORT}}:27017 {{MONGO_IMAGE}}
echo "Waiting for MongoDB to start..."
sleep 3
echo "MongoDB ready on port {{MONGO_PORT}}"
# Stop MongoDB container
mongo-stop:
#!/usr/bin/env bash
if {{DOCKER}} ps -a --format '{{"{{.Names}}"}}' | grep -q "^{{MONGO_CONTAINER}}$"; then
{{DOCKER}} rm -f {{MONGO_CONTAINER}} > /dev/null
echo "MongoDB container stopped"
fi
# Start PostgreSQL for testing
pg-start:
#!/usr/bin/env bash
set -euo pipefail
if {{DOCKER}} ps -a --format '{{"{{.Names}}"}}' | grep -q "^{{PG_CONTAINER}}$"; then
echo "Removing existing container {{PG_CONTAINER}}..."
{{DOCKER}} rm -f {{PG_CONTAINER}} > /dev/null
fi
echo "Starting PostgreSQL on port {{PG_PORT}}..."
{{DOCKER}} run -d --name {{PG_CONTAINER}} \
-p {{PG_PORT}}:5432 \
-e POSTGRES_USER={{PG_USER}} \
-e POSTGRES_PASSWORD={{PG_PASS}} \
-e POSTGRES_DB={{PG_DB}} \
{{PG_IMAGE}}
echo "Waiting for PostgreSQL to be ready..."
for i in $(seq 1 30); do
if {{DOCKER}} exec {{PG_CONTAINER}} pg_isready -U {{PG_USER}} > /dev/null 2>&1; then
echo "PostgreSQL ready on port {{PG_PORT}}"
exit 0
fi
sleep 1
done
echo "PostgreSQL failed to start within 30 seconds"
exit 1
# Stop PostgreSQL container
pg-stop:
#!/usr/bin/env bash
if {{DOCKER}} ps -a --format '{{"{{.Names}}"}}' | grep -q "^{{PG_CONTAINER}}$"; then
{{DOCKER}} rm -f {{PG_CONTAINER}} > /dev/null
echo "PostgreSQL container stopped"
fi
# Format code
fmt:
go fmt ./...
# Lint code
lint:
golangci-lint run ./...
# Tidy dependencies
tidy:
go mod tidy
# Clean up containers and test cache
clean: mongo-stop pg-stop
go clean -testcache
# Install mise tools
tools:
mise install
# Run vulnerability check
vulncheck:
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
# Check for outdated dependencies
depcheck:
go list -m -u all | grep '\[' || echo "All dependencies are up to date"
# Run benchmarks
bench:
go test -bench=. -benchmem ./sqlite/...
# Create and push a new release tag (bumps patch version)
release:
./scripts/release.sh