-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.sh
More file actions
executable file
·87 lines (72 loc) · 1.53 KB
/
pipeline.sh
File metadata and controls
executable file
·87 lines (72 loc) · 1.53 KB
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
#!/bin/bash
set -e
download_deps(){
go mod download
}
cleanup(){
# if pkill not available
# pkill votingapp || ps aux | grep votingapp | awk 'print $1' | head -1 | xargs kill 9
pkill votingapp
rm -rf build
}
unit_test(){
go test
}
build(){
go build -o build/votingapp
cp -r ./ui ./build
}
run(){
pushd build
# run with redis in docker
# docker run -p 6379:6379 -d redis || true
# REDIS=localhost:6379 ./votingapp &
./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:5000/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
}
pushd src/votingapp
download_deps
cleanup || true
unit_test
build
run
popd
retry test