-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest
executable file
·80 lines (63 loc) · 1.5 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
75
76
77
78
79
80
#!/usr/bin/env bash
#
# Usage:
# test
#
# This program tests the cyverse/irods base image by creating an image based on
# it and verifying that iRODS is working on that image.
set -o errexit -o nounset
BASE_DIR="$(dirname "$(realpath --canonicalize-existing "$0")")"
readonly BASE_DIR
declare -rA PROG_MSGS=(
[before_start]='Resolving host name'
[after_start]='after_start received'
[before_stop]='before_stop received'
[after_stop]='Stopping PostgreSQL'
)
main() {
docker buildx build --tag test-image "$BASE_DIR"/test-artifacts
docker run --rm --name test-container test-image | test_container
printf 'PASSED\n'
}
test_container() {
local msgLine
verify_start_msg before_start
verify_start_msg after_start
while read -r msgLine; do
if [[ "$msgLine" == Ready ]]; then
break
fi
done
if [[ "$(docker exec test-container ./irodsctl status)" =~ 'No iRODS server running' ]]; then
printf 'iRODS failed to start\n' >&2
exit 1
fi
docker stop test-container > /dev/null
verify_stop_msg before_stop
verify_stop_msg after_stop
}
verify_start_msg() {
local state="$1"
local msgLine
while read -r msgLine; do
if [[ "$msgLine" == "${PROG_MSGS["$state"]}" ]]; then
break
fi
if [[ "$msgLine" == Ready ]]; then
printf '%s not triggered\n' "$state" >&2
exit 1
fi
done
}
verify_stop_msg() {
local state="$1"
local msgLine
while read -r msgLine; do
if [[ "$msgLine" == "${PROG_MSGS["$state"]}" ]]; then
return
fi
done
printf '%s not triggered\n' "$state" >&2
exit 1
}
main "$@"