-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline-samples.sh
executable file
·131 lines (107 loc) · 2.35 KB
/
pipeline-samples.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
install_tools(){
# install go 1.3
# install jq
echo "Installing tools based on current operating sytem..."
}
install_deps(){
go mod download
echo $?
}
unit_test(){
set -e
go test
set +e
echo $?
}
build(){
rm -r build
echo $?
mkdir -p ./build
echo $?
# option 1: using flags
set -e
go build -o ./build/votingapp
set +e
echo $?
# option 2: inline
# go build -o build ./src/votingapp || exit 1
# option 3: check variable
# if [ $? -gt 0 ]; then
# exit 1
# fi
# option 4: check command
# if ! go build -o build ./src/votingapp; then
# exit 1
# fi
cp -r ui build
echo $?
}
integration_test(){
run_app(){
# kill application
pkill votingapp
# run application
pushd build
./votingapp &
echo $?
popd
}
run_tests(){
# test api with curl (test serialization and broken contract)
curl \
--url http://localhost:5000/vote \
--request POST \
--data '{"topics":["Dev", "Ops"]}' \
--header "Content-Type: application/json"
echo $?
curl \
--url http://localhost:5000/vote \
--request PUT \
--data '{"topic":"Ops"}' \
--header "Content-Type: application/json"
echo $?
winner=$(curl \
--silent \
--url http://localhost:5000/vote \
--request DELETE \
--header "Content-Type: application/json" | jq -r .winner)
echo $?
if [ "$winner" == "Ops" ]; then
echo "Test passed!"
else
echo "Test Failed!"
return 1
fi
}
retry (){
for i in {1..5}; do
echo "Trying $i of 5"
sleep $((i*i))
"$@" && return 0
echo $?
done
return 1
}
run_app
# option1, hack: wait for app to startup
# sleep 1 && run_tests
# option2, must retry when doing integration test
set -e
retry run_tests
set +e
}
deliver(){
#build_number=$(date +%s)
build_number=$(git rev-parse --short HEAD)
tar cvf votingapp"$build_number".tar.gz build
# upload to shared repository (NFS, FTP, ...)
}
pushd ./src/votingapp
install_tools
install_deps
unit_test
build
integration_test
deliver
popd