-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
164 lines (135 loc) · 4.86 KB
/
Makefile
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
ifneq (,$(wildcard ./test/test.env))
include ./test/test.env
export
endif
.SILENT:
.ONESHELL:
.PHONY: docker.db.create
docker.db.create:
ps=$$(docker ps -a -q -f "name=${DB_TEST_CONTAINER}")
if [ -z $$ps ]; then
docker create --name ${DB_TEST_CONTAINER} -p ${DB_TEST_PORT}:5432 -e POSTGRES_PASSWORD=${DB_TEST_PASSWORD} -e POSTGRES_USER=${DB_TEST_USER} ${DB_IMAGE} >/dev/null \
&& echo "${DB_TEST_CONTAINER} container created"
else
echo "${DB_TEST_CONTAINER} container already exists"
fi
.PHONY: docker.db.rm
docker.db.rm: docker.db.down
docker rm ${DB_TEST_CONTAINER} >/dev/null \
&& echo "${DB_TEST_CONTAINER} container removed"
.PHONY: docker.db.up
docker.db.up: docker.db.create
docker start ${DB_TEST_CONTAINER} >/dev/null \
&& echo "${DB_TEST_CONTAINER} container started"
.PHONY: docker.db.down
docker.db.down:
docker stop ${DB_TEST_CONTAINER} >/dev/null \
&& echo "${DB_TEST_CONTAINER} container stopped"
.PHONY: docker.db.restart
docker.db.restart: docker.db.down docker.db.up
.PHONY: db.is_ready
db.is_ready:
echo "waiting for ${DB_TEST_CONTAINER} container"
docker exec ${DB_TEST_CONTAINER} sh -c "until pg_isready -q -h ${DB_TEST_IP}; do sleep 0.5; done" \
&& echo "${DB_TEST_CONTAINER} container is ready"
.PHONY: db.create
db.create: docker.db.up db.is_ready
if docker exec ${DB_TEST_CONTAINER} sh -c "psql -U ${DB_TEST_USER} -lqt | cut -d \| -f 1 | grep -qw ${DB_TEST_NAME}"; then
echo "${DB_TEST_NAME} database already exists"
else
docker exec ${DB_TEST_CONTAINER} createdb --username=${DB_TEST_USER} ${DB_TEST_NAME} \
&& echo "${DB_TEST_NAME} database created"
fi
.PHONY: db.drop
db.drop: docker.db.up db.is_ready
docker exec ${DB_TEST_CONTAINER} dropdb --username=${DB_TEST_USER} ${DB_TEST_NAME} \
&& echo "${DB_TEST_NAME} database dropped"
.PHONY: psql
psql: docker.db.up db.is_ready db.create
docker exec -it ${DB_TEST_CONTAINER} psql -U ${DB_TEST_USER} ${DB_TEST_NAME}
.PHONY: migrate.create
migrate.create: docker.db.up db.is_ready db.create
if [ -z $(n) ]; then
echo "migrate.create require argument 'n' (name) to be set"
exit 1
else
migrate create -ext sql -dir db/migrations -seq $(n)
fi
.PHONY: migrate.up
migrate.up: docker.db.up db.is_ready db.create
migrate -path db/migrations -database ${DB_TEST_URL} up \
&& echo "migrate up done"
.PHONY: migrate.down
migrate.down: docker.db.up db.is_ready db.create
migrate -path db/migrations -database ${DB_TEST_URL} down -all \
&& echo "migrate down done"
.PHONY: sqlc
sqlc: migrate.up
sqlc generate -f db/sqlc.yaml \
&& echo "sqlc generate done"
.PHONY: docker.gotenberg.create
docker.gotenberg.create:
ps=$$(docker ps -a -q -f "name=${GOTENBERG_TEST_CONTAINER}")
if [ -z $$ps ]; then
docker create --name ${GOTENBERG_TEST_CONTAINER} -p ${GOTENBERG_TEST_PORT}:3000 ${GOTENBERG_IMAGE} >/dev/null \
&& echo "${GOTENBERG_TEST_CONTAINER} container created"
else
echo "${GOTENBERG_TEST_CONTAINER} container already exists"
fi
.PHONY: docker.gotenberg.rm
docker.gotenberg.rm: docker.gotenberg.down
docker rm ${GOTENBERG_TEST_CONTAINER} >/dev/null \
&& echo "${GOTENBERG_TEST_CONTAINER} container removed"
.PHONY: docker.gotenberg.up
docker.gotenberg.up: docker.gotenberg.create
docker start ${GOTENBERG_TEST_CONTAINER} >/dev/null \
&& echo "${GOTENBERG_TEST_CONTAINER} container started"
.PHONY: docker.gotenberg.down
docker.gotenberg.down:
docker stop ${GOTENBERG_TEST_CONTAINER} >/dev/null \
&& echo "${GOTENBERG_TEST_CONTAINER} container stopped"
.PHONY: docker.gotenberg.restart
docker.gotenberg.restart: docker.gotenberg.down docker.gotenberg.up
.PHONY: gotenberg.is_ready
gotenberg.is_ready:
echo "waiting for ${GOTENBERG_TEST_CONTAINER} container"
until curl -s --request GET "http://${GOTENBERG_TEST_IP}:${GOTENBERG_TEST_PORT}/health" | grep -q 'chromium":{"status":"up'; do sleep 0.5; done \
&& echo "${GOTENBERG_TEST_CONTAINER} container is ready"
.PHONY: test.cover
test.cover: docker.db.up db.is_ready docker.gotenberg.up gotenberg.is_ready
mkdir -p out
go test -coverprofile out/coverage.out -tags integration ./...
.PHONY: test.cover.html
test.cover.html:
go tool cover -html out/coverage.out
.PHONY: test.unit.all
test.unit.all:
go test ./... -timeout 30s
.PHONY: test.unit
test.unit:
if [ -z $(run) ]; then
echo "test.unit require argument 'run' to be set"
exit 1
else
go test ./... -timeout 30s -run=$(run)
fi
.PHONY: test.it.db.all
test.it.db.all: docker.db.up db.is_ready
+ go test -count 1 -tags integration ./internal/db
.PHONY: test.it.db
test.it.db: docker.db.up db.is_ready
if [ -z $(run) ]; then
echo "migrate.it.db require argument 'run' to be set"
exit 1
else
go test -count 1 -tags integration ./internal/db -run=$(run)
fi
.PHONY: test.it.gotenberg.all
test.it.gotenberg.all: docker.gotenberg.up gotenberg.is_ready
+ go test -count 1 -tags integration ./internal/render
.PHONY: mock
mock:
mockery --config test/mockery.yaml
.PHONY: clean
clean:
rm -rf out