-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·74 lines (52 loc) · 1.57 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
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
#!/usr/bin/env bash
set -e
wait_for_postgres() {
echo "Waiting 60s for Postgres"
for i in {1..60}; do
if pg_isready -h localhost -U postgres; then
break
fi
sleep 1 || exit 1
if [[ $i = 60 ]]; then
echo "TIMEOUT: 60s.. Exiting.."
exit 1
fi
done
}
cleanup_integration_environment() {
echo "Removing integration environment in docker compose"
docker-compose -f docker-compose.db.yml down -t 1 ||:
docker-compose -f docker-compose.svc.yml down -t 1 ||:
docker network rm integration ||:
}
setup_integration_environment() {
# Destroy all
cleanup_integration_environment
echo "Setting up integration environment in docker compose"
# Rebuild network + db
docker network create --attachable integration
docker-compose -f docker-compose.db.yml up -d
wait_for_postgres
# Hydrate db
createdb -h localhost -U postgres person
for file in sql/*.sql; do
echo "Loading file: ${file}"
psql -h localhost -U postgres -d person -v ON_ERROR_STOP=1 < "${file}"
done
# Rebuild svc
docker-compose -f docker-compose.svc.yml up -d
echo "Wait 3s for services to startup..."
sleep 3
}
setup_integration_environment
trap cleanup_integration_environment EXIT
echo "Running curl..."
# Validate these requests don't return failing exit code
curl -f -XPOST "localhost:9999/person?name=ryan&age=88"
curl -f -XGET "localhost:9999/person?name=ryan"
echo "Curl Tests Passed"
echo "Running go..."
# Run a bunch of tests managed by go
export PERSON_SVC_TEST_SERVER_URL="http://localhost:9999"
go test ./test
echo "Go tests passed"