-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpipeline.sh
executable file
·78 lines (65 loc) · 1.46 KB
/
pipeline.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e
# install deps
deps(){
go get github.com/gorilla/websocket
go get github.com/labstack/echo
go get github.com/go-redis/redis
}
# cleanup
cleanup(){
pkill votingapp || ps aux | grep votingapp | awk {'print $1'} | head -1 | xargs kill -9
rm -rf build
}
# build
build(){
mkdir build
go build -o ./build ./src/votingapp
cp -r ./src/votingapp/ui ./build
docker run -p 6379:6379 -d redis || true
pushd build
./votingapp &
popd
}
retry(){
n=0
interval=5
retries=3
$@ && return 0
until [ $n -ge $retries ]
do
n=$(($n+1))
echo "Retrying...$n of $retries, wait for $interval seconds"
sleep $interval
$@ && return 0
done
return 1
}
# test
test() {
votingurl='http://localhost/vote'
curl --url $votingurl \
--request POST \
--data '{"topics":["dev", "ops"]}' \
--header "Content-Type: application/json"
curl --url $votingurl \
--request PUT \
--data '{"topic": "dev"}' \
--header "Content-Type: application/json"
winner=$(curl --url $votingurl \
--request DELETE \
--header "Content-Type: application/json" | jq -r '.winner')
echo "Winner IS "$winner
expectedWinner="dev"
if [ "$expectedWinner" == "$winner" ]; then
echo 'TEST PASSED'
return 0
else
echo 'TEST FAILED'
return 1
fi
}
deps
cleanup || true
build
retry test