|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2022 Adevinta |
| 4 | + |
| 5 | +set -u -e |
| 6 | + |
| 7 | +cd "$(dirname $0)/.." |
| 8 | + |
| 9 | +case $# in |
| 10 | +1) |
| 11 | + ARG=$1 |
| 12 | + ;; |
| 13 | +*) |
| 14 | + echo "usage: $0 <read|master>" >&2 |
| 15 | + exit 2 |
| 16 | + ;; |
| 17 | +esac |
| 18 | + |
| 19 | +COMPOSE_OPTIONS="" |
| 20 | +case $ARG in |
| 21 | +"read") |
| 22 | + CONFIG_FILE="_resources/config/e2e-read-replica.toml" |
| 23 | + SERVICE="postgresql-e2e-slave" |
| 24 | + echo "using the read replica database" |
| 25 | + ;; |
| 26 | +"master") |
| 27 | + CONFIG_FILE="_resources/config/e2e-master.toml" |
| 28 | + SERVICE="postgresql-e2e-master" |
| 29 | + echo "using the master database" |
| 30 | + ;; |
| 31 | +*) |
| 32 | + echo "usage: $0 <read|master>" >&2 |
| 33 | + exit 2 |
| 34 | + ;; |
| 35 | +esac |
| 36 | + |
| 37 | + |
| 38 | +# Start postgress databases. |
| 39 | +docker-compose -f _resources/docker-compose-e2e.yml -p "e2e" up -d $SERVICE |
| 40 | + |
| 41 | +# Set up schema for the test db. |
| 42 | +set +e |
| 43 | +rm -rf /tmp/vulnerability-db |
| 44 | +set -e |
| 45 | +git clone --single-branch --branch master https://github.com/adevinta/vulnerability-db.git /tmp/vulnerability-db |
| 46 | +docker run --net=host -v /tmp/vulnerability-db/db:/flyway/sql flyway/flyway:"${FLYWAY_VERSION:-8}-alpine" \ |
| 47 | + -user=vulndb -password=vulndb -url=jdbc:postgresql://127.0.0.1:5434/vulndbtest -baselineOnMigrate=true migrate |
| 48 | + |
| 49 | +# Loaf fixtures in the test db. |
| 50 | +TestDBPort=5434 go run e2e/fixtures.go _resources/e2e/fixtures/ |
| 51 | + |
| 52 | +# Give time to the fixtures data to be replicated to the read replica. |
| 53 | +sleep 5 |
| 54 | + |
| 55 | +# Kill any possible running server. |
| 56 | +set +e |
| 57 | +pkill vulnerability-db-api |
| 58 | +set -e |
| 59 | + |
| 60 | +echo "RUNNING vulnerability-db-api" |
| 61 | +go install ./... |
| 62 | +vulnerability-db-api -c $CONFIG_FILE & |
| 63 | + |
| 64 | +# Run e2e tests. |
| 65 | +echo "RUNNING e2e tests" |
| 66 | +docker-compose -f _resources/docker-compose-e2e.yml -p "e2e" run e2e |
| 67 | + |
| 68 | +# Clean up resurces. |
| 69 | +set +e |
| 70 | +pkill vulnerability-db-api |
| 71 | +set -e |
| 72 | +docker-compose -f _resources/docker-compose-e2e.yml -p "e2e" rm -s -f -v |
| 73 | + |
0 commit comments