-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·95 lines (78 loc) · 2.33 KB
/
run-tests.sh
File metadata and controls
executable file
·95 lines (78 loc) · 2.33 KB
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
#!/bin/bash
set -euo pipefail
# Disclaimer: I am no bash wizard
# The first argument to the script.
# If no argument is specified, it runs the tests and cleans up.
# Possible values:
# build build services
# logs show logs
# dont_clean_up dont run docker-compose down
# only_models only run the models tests
cmd=${1:-}
# If the first argument is logs, you can specifiy the services for which to show
# logs for with the second argument
logs_service=${2:-}
# Set up some helper variables
dont_clean_up=${dont_clean_up:-}
show_logs=${show_logs:-}
only_models_tests=${only_models_tests:-}
git_branch=$(git rev-parse --abbrev-ref HEAD)
function runComposeCommand() {
docker compose -p osemapitest -f ./tests/docker-compose.yml "$@"
}
function cleanup() {
if [[ -n $show_logs ]]; then
if [[ -z $logs_service ]]; then
runComposeCommand logs
else
runComposeCommand logs "$logs_service"
fi
fi
if [[ -z $dont_clean_up ]]; then
echo 'cleanup!'
runComposeCommand down -v --remove-orphans
fi
}
trap cleanup EXIT
function executeTests() {
runComposeCommand down -v --remove-orphans
# Start database
runComposeCommand up --quiet-pull -d --remove-orphans db
# Allow the dust and database to settle
sleep 3
# Run database migrations from the models package
runComposeCommand run -T --rm osem-api yarn models:db:migrate
# Allow the dust to settle
sleep 3
# Run API tests
if [[ -z $only_models_tests ]]; then
runComposeCommand up --quiet-pull -d --force-recreate --remove-orphans osem-api mailhog mosquitto redis-stack
#Allow the dust to settle
sleep 3
runComposeCommand exec -T osem-api yarn mocha --exit tests/waitForHttp.js tests/tests.js
runComposeCommand stop osem-api
fi
# Run Models tests
# use ./node_modules/.bin/mocha because the workspace does not have the devDependency mocha
runComposeCommand run -T --workdir=/usr/src/app/packages/models osem-api ../../node_modules/.bin/mocha --exit test/index
}
case "$cmd" in
"build")
runComposeCommand build osem-api
exit 0
;;
"logs")
shift # remove "logs" from $@
show_logs="true"
if [[ $logs_service == "all" ]]; then
logs_service=""
fi
;;
"dont_clean_up")
dont_clean_up="true"
;;
"only_models")
only_models_tests="true"
;;
esac
executeTests