generated from DEFRA/ffc-template-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·74 lines (59 loc) · 1.63 KB
/
test
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
#!/usr/bin/env sh
set -e
projectRoot="$(a="/$0"; a=${a%/*}; a=${a:-.}; a=${a#/}/; cd "$a/.." || return; pwd)"
service="ffc-pay-submission"
show_help() {
echo "
Usage: scripts/test [OPTION...]
Run tests.
Options:
-w, --watch watch tests
-d, --debug debug tests
-h, --help display this help text
"
}
while :; do
case $1 in
-w|--watch)
watch="true"
;;
-d|--debug)
debug="true"
;;
-h|--help) # Call a "show_help" function to display a synopsis, then exit.
show_help
exit
;;
*)
break
esac
shift
done
compose() {
if [ "${watch}" = "true" ]; then
docker compose -f docker-compose.yaml -f docker-compose.test.yaml -f docker-compose.test.watch.yaml -p "${service}-test" $@
elif [ "${debug}" = "true" ]; then
docker compose -f docker-compose.yaml -f docker-compose.test.yaml -f docker-compose.test.watch.yaml -f docker-compose.test.debug.yaml -p "${service}-test" $@
else
docker compose -f docker-compose.yaml -f docker-compose.test.yaml -p "${service}-test" $@
fi
}
(
cd "${projectRoot}"
# Ensure test-output directory exists
mkdir -p test-output
# Guarantee clean environment
compose down -v
docker compose -f docker-compose.migrate.yaml -p "${service}-test" down -v
# Ensure container images are up to date
compose build
docker compose -f docker-compose.migrate.yaml -p "${service}-test" run --rm database-up
# Run tests
if [ "${debug}" = "true" ]; then
compose run --service-ports --rm ${service} ${command}
else
compose run --rm ${service} ${command}
fi
# Clean up
compose down -v
)