File: dbtests.sh

package info (click to toggle)
notary 0.6.1~ds1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,692 kB
  • sloc: python: 1,112; sh: 481; makefile: 181; sql: 155
file content (61 lines) | stat: -rwxr-xr-x 1,981 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env bash

db="$1"

case ${db} in
  mysql*)
    db="mysql"
    dbContainerOpts="--name mysql_tests mysql mysqld --innodb_file_per_table"
    DBURL="server@tcp(mysql_tests:3306)/notaryserver?parseTime=True"
    ;;
  rethink*)
    db="rethink"
    dbContainerOpts="--name rethinkdb_tests rdb-01 --bind all --driver-tls-key /tls/key.pem --driver-tls-cert /tls/cert.pem"
    DBURL="rethinkdb_tests"
    ;;
  postgresql*)
    db="postgresql"
    dbContainerOpts="--name postgresql_tests postgresql -l"
    DBURL="postgres://server@postgresql_tests:5432/notaryserver?sslmode=verify-ca&sslrootcert=/go/src/github.com/theupdateframework/notary/fixtures/database/ca.pem&sslcert=/go/src/github.com/theupdateframework/notary/fixtures/database/notary-server.pem&sslkey=/go/src/github.com/theupdateframework/notary/fixtures/database/notary-server-key.pem"
    ;;
  *)
    echo "Usage: $0 (mysql|rethink)"
    exit 1
    ;;
esac

composeFile="development.${db}.yml"
project=dbtests

function cleanup {
    rm -f bin/notary
    docker-compose -p "${project}_${db}" -f "${composeFile}" kill
    # if we're in CircleCI, we cannot remove any containers
    if [[ -z "${CIRCLECI}" ]]; then
        docker-compose -p "${project}_${db}" -f "${composeFile}" down -v --remove-orphans
    fi
}

clientCmd="make TESTOPTS='-p 1' test"
if [[ -z "${CIRCLECI}" ]]; then
    BUILDOPTS="--force-rm"
else
    clientCmd="make ci && codecov"
fi

set -e
set -x

cleanup

docker-compose -p "${project}_${db}" -f ${composeFile} build ${BUILDOPTS} client

trap cleanup SIGINT SIGTERM EXIT

# run the unit tests that require a DB

docker-compose -p "${project}_${db}" -f "${composeFile}" run --no-deps -d ${dbContainerOpts}
docker-compose -p "${project}_${db}" -f "${composeFile}" run --no-deps \
    -e NOTARY_BUILDTAGS="${db}db" -e DBURL="${DBURL}" \
    -e PKGS="github.com/theupdateframework/notary/server/storage github.com/theupdateframework/notary/signer/keydbstore" \
    client bash -c "${clientCmd}"