-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathintegration-tests.sh
executable file
·172 lines (155 loc) · 3.55 KB
/
integration-tests.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
# Keep track of failures
FAILED=0
# Output a fail message
fail() {
echo ''
echo 'FAIL'
echo $1
let "FAILED += 1"
}
# Show progress when tests pass
pass() {
echo -n '.'
}
# Output a message and return with no error when all tests has passed
finished() {
echo ''
if [[ $FAILED -ne 0 ]]; then
echo 'There were failed integration tests'
else
echo 'All integration tests passed'
fi
exit $FAILED
}
# Bin to use in tests
BIN=./build/wiki
# Test that error message and usage is printed if no query
$BIN > /dev/null 2>&1
STATUS=$?
if [[ $STATUS -ne 1 ]]; then
fail 'Error message and usage not printed if no output'
exit 1
fi
pass
# Test that standard usage prints a link to page
OUTPUT="$($BIN golang)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Read more: https://en.wikipedia.org/wiki/Go"
if [ $? -ne 0 ];then
fail 'Standard usage did not output link to page'
fi
pass
# Test that short flag does not print a link to page
OUTPUT="$($BIN -s golang)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Read more: https://en.wikipedia.org/wiki/Go"
if [ $? -eq 0 ];then
fail 'Short flag did output link to page'
fi
pass
# Test that language flag works
OUTPUT="$($BIN -l sv c++)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Read more: https://sv.wikipedia.org/wiki/C"
if [ $? -ne 0 ];then
fail 'Language flag did not work'
fi
pass
# Test that language enviroment works
OUTPUT="$(WIKI_LANG=sv $BIN c++)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Read more: https://sv.wikipedia.org/wiki/C"
if [ $? -ne 0 ];then
fail 'Language flag did not work'
fi
pass
# Test that no color flag works
OUTPUT="$($BIN -n golang)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "\[32m"
if [ $? -eq 0 ];then
fail 'No color flag did not work'
fi
pass
# Test that url flag works
OUTPUT="$($BIN -u http://localhost:8080/w/api.php golang 2>&1)"
STATUS=$?
if [[ $STATUS -eq 0 ]]; then
fail 'Got success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Could not execute request Get http://localhost:8080"
if [ $? -ne 0 ];then
fail 'Url flag did not work'
fi
pass
#Test URL passed as enviroment
OUTPUT="$(WIKI_URL=http://localhost:8080/w/api.php $BIN golang 2>&1)"
STATUS=$?
if [[ $STATUS -eq 0 ]]; then
fail 'Got success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Could not execute request Get http://localhost:8080"
if [ $? -ne 0 ];then
fail 'Url flag did not work'
fi
pass
# Test that no-check-certificate flag works
OUTPUT="$($BIN -no-check-certificate golang)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
echo "$OUTPUT" | grep -q "Read more: https://en.wikipedia.org/wiki/Go"
if [ $? -ne 0 ];then
fail 'Standard usage did not output link to page'
fi
pass
# Test that short flag works
OUTPUT="$($BIN -short golang)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
OUTPUT2="$(echo $OUTPUT | grep -c '.')"
if [ $OUTPUT2 -ne 1 ];then
fail 'Short flag did not work'
fi
pass
# Test that wrap flag works
OUTPUT="$($BIN -w 80 golang)"
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
fail 'Did not get success exit code'
exit 1
fi
OUTPUT2="$(echo $OUTPUT | grep -c '.')"
if [ $OUTPUT2 -ne 1 ];then
fail 'Wrap flag did not work'
fi
pass
finished