-
Notifications
You must be signed in to change notification settings - Fork 4
/
task.sh
executable file
·129 lines (115 loc) · 2.47 KB
/
task.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
#!/bin/bash
container_api="denops-mock-api"
container_network="denops-mock-net"
function isNetworkExist() {
id=$(docker network ls --filter name=denops-mock-net --format "{{.ID}}")
if [ "${id}" != "" ];then
echo true
else
echo false
fi
}
function isContainerRunning() {
state=$(docker ps -a -f "name=^${1}$" --format "{{.State}}")
if [ "${state}" = "running" ]; then
echo true
else
echo false
fi
}
function isContainerExist() {
state=$(docker ps -a -f "name=^${1}$" --format "{{.State}}")
if [ "${state}" != "" ]; then
echo true
else
echo false
fi
}
function removeContainers() {
for name in $@; do
if ! $(isContainerExist $name); then
continue
fi
if $(isContainerRunning $name); then
docker kill ${name} && sleep 0.5
fi
docker rm ${name}
done
}
function doUp() {
if ! $(isNetworkExist $container_network); then
echo "create container network: ${container_network}"
docker network create ${container_network}
fi
if ! $(isContainerExist $container_api); then
echo "start container: ${container_api}"
docker run --rm -v ${PWD}:/mock --name ${container_api} \
--net ${container_network} \
-p 9999:4010 \
-d stoplight/prism:4.10.1 mock \
-h 0.0.0.0 /mock/swagger.yaml
docker run --rm --net $container_network jwilder/dockerize -timeout 180s -wait http://${container_api}:4010/containers/json
fi
}
function doDown() {
if $(isContainerExist $container_api); then
docker kill ${container_api}
fi
if $(isNetworkExist $container_network); then
docker network rm ${container_network}
fi
}
function doTest() {
deno test -A --unstable --coverage=cov .
exit_code=$?
if [ ${exit_code} != 0 ]; then
exit ${exit_code}
fi
case $1 in
cov)
deno coverage cov
rm -rf cov
;;
*)
;;
esac
}
function doUpdateDeps() {
udd denops/docker/deps.ts
}
function usage() {
cat << EOF
Usage:
task.sh {action} [{argument}...]
Avaliable action:
test:run run tests
test:cov run tests and output soverage
mock:api:up run docker's mock api container
mock:api:down remove docker's mock api container and network
EOF
}
function main() {
case $1 in
test:run)
doUp
doTest $2
;;
test:cov)
doUp
doTest $2 cov
;;
mock:api:up)
doUp
;;
mock:api:down)
doDown
;;
deps:update)
doUpdateDeps
;;
*)
usage
;;
esac
}
main $@