-
Notifications
You must be signed in to change notification settings - Fork 171
/
utils.sh
100 lines (87 loc) · 2.56 KB
/
utils.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /bin/bash
set -e
ROOT=$(realpath ../..)
function check_docker_connectivity {
if docker version >/dev/null 2>/dev/null ; then
true
else
echo "Cannot connect to docker daemon."
if [[ $EUID -ne 0 ]]; then
echo "Maybe you need to run this as root."
fi
false
fi
}
function pull_docker_image {
echo -e "\n - Pulling $DOCKER_IMAGE\n"
docker pull "$DOCKER_IMAGE"
if docker ps -a -f name="$DOCKER_NAME" | grep "$DOCKER_NAME" > /dev/null ; then
docker rm -f "$DOCKER_NAME"
fi
}
function stop {
if status ; then
echo -e "\n - Removing $DOCKER_NAME\n"
docker rm -f "$DOCKER_NAME" >/dev/null
else
echo "NOT RUNNING"
fi
}
function status {
docker ps -f name="$DOCKER_NAME" | grep "$DOCKER_NAME" > /dev/null
}
function run_tests {
BACKEND="$1"
TEST="$2"
if [[ -z "$BACKEND" ]]; then
echo "missing backend"
return 1
fi
PLIKD_CONFIG="$ROOT/testing/$BACKEND/plikd.cfg"
export PLIKD_CONFIG
export BACKEND
if [[ -z "$TEST" ]]; then
( cd "$ROOT/plik" && GORACE="halt_on_error=1" go test -count=1 -race ./... )
( cd "$ROOT/server/server" && GORACE="halt_on_error=1" go test -count=1 -race ./... )
# Run metadata backend tests
if [[ "$BACKEND" == "postgres" ]] || [[ "$BACKEND" == "mariadb" ]] || [[ "$BACKEND" == "mysql" ]] || [[ "$BACKEND" == "mssql" ]]; then
( cd "$ROOT/server/metadata" && GORACE="halt_on_error=1" go test -count=1 -race ./... )
fi
else
( cd "$ROOT/plik" && GORACE="halt_on_error=1" go test -count=1 -v -race -run "$TEST" )
( cd "$ROOT/server/server" && GORACE="halt_on_error=1" go test -count=1 -race ./... )
# Run metadata backend test
if [[ "$BACKEND" == "postgres" ]] || [[ "$BACKEND" == "mariadb" ]] || [[ "$BACKEND" == "mysql" ]] || [[ "$BACKEND" == "mssql" ]]; then
( cd "$ROOT/server/metadata" && GORACE="halt_on_error=1" go test -count=1 -v -race -run "$TEST" )
fi
fi
}
function run_cmd {
case "$CMD" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
test)
stop
start
run_tests "$BACKEND" "$TEST"
;;
status)
if status ; then
docker ps -f name="$DOCKER_NAME"
else
echo "NOT RUNNING"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status|test}"
exit 1
esac
}