-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·48 lines (38 loc) · 1.34 KB
/
test.sh
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
#!/bin/sh
set -e
log2() {
echo "$@" > /dev/stderr
}
print2() {
printf "$@" > /dev/stderr
}
export GOV_TEST_POSTGRES_USERNAME=postgres
export GOV_TEST_POSTGRES_PASSWORD=admin
export GOV_TEST_POSTGRES_DB=postgres
export GOV_TEST_POSTGRES_HOST=localhost
export GOV_TEST_POSTGRES_PORT=5433
container_id=$(docker container run --detach \
--publish $GOV_TEST_POSTGRES_PORT:5432 \
--env POSTGRES_USER="$GOV_TEST_POSTGRES_USERNAME" \
--env POSTGRES_PASSWORD="$GOV_TEST_POSTGRES_PASSWORD" \
--env POSTGRES_DB="$GOV_TEST_POSTGRES_DB" \
--env PGDATA="/var/lib/postgresql/data/pgdata" \
--env POSTGRES_HOST_AUTH_METHOD="scram-sha-256" \
--env POSTGRES_INITDB_ARGS="--encoding UTF8 --locale=C --auth-local=trust --auth-host=scram-sha-256" \
--env LANG="C" \
postgres:alpine)
log2 "started container $container_id"
cleanup() {
log2 "stopping container $container_id"
docker container stop "$container_id" > /dev/stderr
docker container rm --force --volumes "$container_id" > /dev/stderr
}
trap cleanup EXIT
dsn="postgresql://$GOV_TEST_POSTGRES_USERNAME:$GOV_TEST_POSTGRES_PASSWORD@$GOV_TEST_POSTGRES_HOST:$GOV_TEST_POSTGRES_PORT/$GOV_TEST_POSTGRES_DB"
log2 "waiting for container $container_id"
until psql $dsn -A -t -c "select 'ok';" > /dev/null 2>&1; do
sleep 0.5
print2 "."
done
print2 "\n"
go test -trimpath -ldflags "-w -s" -race "$@"