-
Notifications
You must be signed in to change notification settings - Fork 7
/
e2e.bats
155 lines (134 loc) · 4.63 KB
/
e2e.bats
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bats
COMMAND="${COMMAND:/-$BATS_TEST_DIRNAME}"
: ${CMD:=$GOPATH/bin/gaos}
setup() {
TEST_SCENARIO_PASS='./examples/example.json'
TEST_SCENARIO_FAIL='/dev/null'
TEST_EXECUTES_PASS='product,search'
TEST_EXECUTES_FAIL='product;search'
TEST_REGISTRY='localhost:5000'
TEST_ENV_BAD='some'
TEST_ENV_D4R='docker'
TEST_ENV_K8S='k8s'
}
@test "project: clear" {
run rm -rf "$CMD"
echo "$output"
[ "$status" -eq 0 ]
}
@test "project: should build" {
run go build -o "$CMD" .
echo "$output"
[ "$status" -eq 0 ]
}
@test "project: run: should run" {
run ${CMD}
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 0 ]
[[ $output = *"" ]]
}
@test "project: run: should not run without scenario" {
run ${CMD} run
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 1 ]
[[ $output = *"Unable to read scenario file"* ]]
}
@test "project: run: should not run with non exist scenario" {
run timeout --preserve-status 5 ${CMD} run -s $TEST_SCENARIO_FAIL
echo "status = ${status}">&2
[ "$status" -eq 1 ]
}
@test "project: run: should run scenario" {
run timeout --preserve-status 5 ${CMD} run -s $TEST_SCENARIO_PASS
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 0 ]
[[ $output = *"HTTP server started for [product]"* ]]
[[ $output = *"Servers are stopping..."* ]]
[[ $output = *"Http server closed"* ]]
}
@test "project: run: should not run scenario with bad custom executes" {
run timeout --preserve-status 5 ${CMD} run -s $TEST_SCENARIO_PASS -x $TEST_EXECUTES_FAIL
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 1 ]
[[ $output = *"There are no servers to run"* ]]
}
@test "project: run: should run with scenario and custom executes" {
run timeout --preserve-status 5 ${CMD} run -s $TEST_SCENARIO_PASS -x $TEST_EXECUTES_PASS
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 0 ]
[[ $output = *"[9080] HTTP server started for [product]"* ]]
[[ $output = *"[9081] HTTP server started for [search]"* ]]
[[ $output = *"Servers are stopping..."* ]]
[[ $output = *"[9080] Http server closed"* ]]
[[ $output = *"[9081] Http server closed"* ]]
}
@test "project: start: should not start without scenario" {
run ${CMD} start
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 1 ]
[[ $output = *"Unable to read scenario file"* ]]
}
@test "project: start: should not start without environment" {
run ${CMD} start -s $TEST_SCENARIO_PASS
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 1 ]
[[ $output = *"Unexpected environment given"* ]]
}
@test "project: start: check prerequisites" {
run command -v kind
[ "$status" -eq 0 ]
run command -v kubectl
[ "$status" -eq 0 ]
run command -v docker
[ "$status" -eq 0 ]
run docker ps
[ "$status" -eq 0 ]
run kubectl config use-context kind-kind
[ "$status" -eq 0 ]
}
@test "project: start: docker: should start deployment and push to docker" {
run timeout --signal INT --preserve-status 150 ${CMD} start -s $TEST_SCENARIO_PASS -e $TEST_ENV_D4R -r $TEST_REGISTRY
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 0 ]
[[ $output = *"Docker: Creating image: [product]"* ]]
[[ $output = *"Container is running."* ]]
[[ $output = *"Docker: Creating image: [search]"* ]]
[[ $output = *"Container is running."* ]]
[[ $output = *"Containers are stopping..."* ]]
[[ $output = *"Docker container is stopped"* ]]
[[ $output = *"Docker container is stopped"* ]]
}
@test "project: start: k8s: should start deployment and push to kind using registry" {
run ${CMD} start -s $TEST_SCENARIO_PASS -e $TEST_ENV_K8S -r $TEST_REGISTRY -n default --replica 1
echo "status = ${status}">&2
echo "output = ${output}">&2
[ "$status" -eq 0 ]
[[ $output = *"Docker: Creating image: [product]"* ]]
[[ $output = *"Service [product-service] created on port [9080]"* ]]
[[ $output = *"Docker: Creating image: [search]"* ]]
[[ $output = *"Service [search-service] created on port [9081]"* ]]
}
@test "project: start: k8s: check false-positives" {
run kubectl get deployment product-deployment -n default
[ "$status" -eq 0 ]
run kubectl get deployment search-deployment -n default
[ "$status" -eq 0 ]
run kubectl get service product-service -n default
[ "$status" -eq 0 ]
run kubectl get service search-service -n default
[ "$status" -eq 0 ]
run kubectl get pods --selector=app=product
[ "$status" -eq 0 ]
[[ ! $output = *"No resources found."* ]]
run kubectl get pods --selector=app=search
[ "$status" -eq 0 ]
[[ ! $output = *"No resources found."* ]]
}