-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·89 lines (70 loc) · 1.91 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
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -e
set -x
function main()
{
test "$1" "$2"
}
function test()
(
local mode="$1"
local goversion="$2"
local path_harness="."
local path_test="./.tmp-test"
local ci_test_path="${path_harness}/.ci/${mode}"
if [ -d "${path_test}" ]; then
rm -rf "${path_test}"
fi
cp -ap "${ci_test_path}" "${path_test}"
cd ${path_test}
mkdir "./.my127ws/"
cp -ap "../${path_harness}/"* "./.my127ws/"
export COMPOSE_PROJECT_NAME=ci-go-sample
ws set go.version "\"${goversion}\""
ws install
local lockedversion
lockedversion=$(ws get go.version)
if [ "$lockedversion" != "$goversion" ]; then
echo "Expected a locked go.version value of $goversion, but got $lockedversion."
exit 1
fi
ws helm kubeval qa
ws go generate
ws go test
ws disable
ws enable
sleep 5
verify_or_exit "${path_test}" "${ci_test_path}"
local build_prod="../${ci_test_path}/.build-prod"
if [[ -f "${build_prod}" ]]; then
ws build-prod
fi
)
function verify_or_exit() {
local path_test="$1"
local ci_test_path="$2"
local expected_containers="../${ci_test_path}/.expected_containers"
if ! docker compose ps --services --filter "status=running" | grep --silent -Fxe app; then
echo "The app container has stopped running unexpectedly."
exit 1
fi
if [[ -f "${expected_containers}" ]]; then
while read -r container; do
if ! docker compose ps --services --filter "status=running" | grep --silent -Fxe "$container"; then
echo "The ${container} container is not running, but it should be."
docker compose logs --tail 100 "$container"
exit 1
fi
done < "${expected_containers}"
fi
}
function clean()
{
local path_test="./.tmp-test"
if [ -d "$path_test" ]; then
(cd $path_test && ws destroy)
rm -rf $path_test
fi
}
trap 'clean' EXIT
main "$@"