-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun-e2e.sh
executable file
·69 lines (56 loc) · 1.57 KB
/
run-e2e.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
#!/bin/bash
# Copyright 2022 Adevinta
set -u -e
cd "$(dirname $0)/.."
case $# in
1)
ARG=$1
;;
*)
echo "usage: $0 <read|master>" >&2
exit 2
;;
esac
case $ARG in
"read")
CONFIG_FILE="_resources/config/e2e-read-replica.toml"
SERVICE="postgresql-e2e-slave"
echo "using the read replica database"
;;
"master")
CONFIG_FILE="_resources/config/e2e-master.toml"
SERVICE="postgresql-e2e-master"
echo "using the master database"
;;
*)
echo "usage: $0 <read|master>" >&2
exit 2
;;
esac
# Start postgress databases.
docker compose -f _resources/docker-compose-e2e.yml -p e2e up --quiet-pull -d $SERVICE
# Set up schema for the test db.
VDB=$(mktemp -d)
git clone --single-branch --branch master https://github.com/adevinta/vulnerability-db.git "$VDB"
docker run --net=host -v "$VDB/db/sql":/flyway/sql flyway/flyway:"${FLYWAY_VERSION:-10}-alpine" \
-user=vulndb -password=vulndb -url=jdbc:postgresql://127.0.0.1:5434/vulndbtest -baselineOnMigrate=true migrate
rm -rf "$VDB"
# Loaf fixtures in the test db.
TestDBPort=5434 go run e2e/fixtures.go _resources/e2e/fixtures/
# Give time to the fixtures data to be replicated to the read replica.
sleep 5
# Kill any possible running server.
set +e
pkill vulnerability-db-api
set -e
echo "RUNNING vulnerability-db-api"
go install ./...
vulnerability-db-api -c $CONFIG_FILE &
# Run e2e tests.
echo "RUNNING e2e tests"
docker compose -f _resources/docker-compose-e2e.yml -p "e2e" run --quiet-pull e2e
# Clean up resurces.
set +e
pkill vulnerability-db-api
set -e
docker compose -f _resources/docker-compose-e2e.yml -p "e2e" rm -s -f -v