forked from qdm12/deunhealth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_test.sh
64 lines (49 loc) · 3.48 KB
/
integration_test.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
#!/bin/sh
finish() {
set +e
echo "Removing containers..."
[ "$deunhealthID" != "" ] && docker rm -f "$deunhealthID"
[ "$nohealthID" != "" ] && docker rm -f "$nohealthID"
[ "$healthyID" != "" ] && docker rm -f "$healthyID"
[ "$unhealthyID" != "" ] && docker rm -f "$unhealthyID"
[ "$nohealthMarkedID" != "" ] && docker rm -f "$nohealthMarkedID"
[ "$healthyMarkedID" != "" ] && docker rm -f "$healthyMarkedID"
[ "$unhealthyMarkedID" != "" ] && docker rm -f "$unhealthyMarkedID"
[ "$nohealthIDLinkedID" != "" ] && docker rm -f "$nohealthIDLinkedID"
echo "done"
}
trap finish EXIT
set -e
docker --version
[ $? = 0 ] || ( echo "Docker not installed!"; exit 1 )
# docker build -t qmcgaw/deunhealth .
healthFlags="--health-start-period=0s --health-interval=40ms --health-retries=1"
restartOnUnhealthyLabel="--label deunhealth.restart.on.unhealthy=true"
linkedOnUnhealthyLabel="--label deunhealth.restart.with.unhealthy.container="
echo "launching test containers"
nohealthID="$(docker run -d --init alpine:3.15 sleep 30)"
healthyID="$(docker run -d --init --health-cmd='exit 0' $healthFlags alpine:3.15 sleep 30)"
unhealthyID="$(docker run -d --init --health-cmd='exit 1' $healthFlags alpine:3.15 sleep 30)"
nohealthMarkedID="$(docker run -d $restartOnUnhealthyLabel alpine:3.15)"
healthyMarkedID="$(docker run -d --init $restartOnUnhealthyLabel --health-cmd='exit 0' $healthFlags alpine:3.15 sleep 30)"
unhealthyMarkedID="$(docker run -d --init $restartOnUnhealthyLabel --health-cmd='exit 1' $healthFlags alpine:3.15 sleep 30)"
nohealthName="$(docker inspect -f '{{ .Name }}' $nohealthID | sed -r 's/^\///')"
healthyName="$(docker inspect -f '{{ .Name }}' $healthyID | sed -r 's/^\///')"
unhealthyName="$(docker inspect -f '{{ .Name }}' $unhealthyID | sed -r 's/^\///')"
nohealthMarkedName="$(docker inspect -f '{{ .Name }}' $nohealthMarkedID | sed -r 's/^\///')"
healthyMarkedName="$(docker inspect -f '{{ .Name }}' $healthyMarkedID | sed -r 's/^\///')"
unhealthyMarkedName="$(docker inspect -f '{{ .Name }}' $unhealthyMarkedID | sed -r 's/^\///')"
nohealthLinkedID="$(docker run -d --init $linkedOnUnhealthyLabel$unhealthyMarkedName alpine:3.15 sleep 30)"
nohealthLinkedName="$(docker inspect -f '{{ .Name }}' $nohealthLinkedID | sed -r 's/^\///')"
echo "launching deunhealth"
deunhealthID="$(docker run -d -v /var/run/docker.sock:/var/run/docker.sock qmcgaw/deunhealth)"
echo "waiting 1 second"
sleep 1
logs="$(docker logs $deunhealthID)"
[ "$(echo $logs | grep -o $nohealthName | wc -l)" = "0" ] || ( echo "Container $nohealthName appears in deunhealth logs"; echo "$logs"; exit 1 )
[ "$(echo $logs | grep -o $healthyName | wc -l)" = "0" ] || ( echo "Container $healthyName appears in deunhealth logs"; echo "$logs"; exit 1 )
[ "$(echo $logs | grep -o $unhealthyName | wc -l)" = "0" ] || ( echo "Container $unhealthyName appears in deunhealth logs"; echo "$logs"; exit 1 )
[ "$(echo $logs | grep -o $nohealthMarkedName | wc -l)" = "0" ] || ( echo "Container $nohealthMarkedName appears in deunhealth logs"; echo "$logs"; exit 1 )
[ "$(echo $logs | grep -o $healthyMarkedName | wc -l)" != "0" ] || ( echo "Container $healthyMarkedName does not appears in deunhealth logs"; echo "$logs"; exit 1 )
[ "$(echo $logs | grep -o $unhealthyMarkedName | wc -l)" != "0" ] || ( echo "Container $unhealthyMarkedName does not appear in deunhealth logs"; echo "$logs"; exit 1 )
[ "$(echo $logs | grep -o $nohealthLinkedName | wc -l)" != "0" ] || ( echo "Container $nohealthLinkedName does not appear in deunhealth logs"; echo "$logs"; exit 1 )