-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttp-dl.bats
268 lines (229 loc) · 6.9 KB
/
http-dl.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env bats
#
# Test http:// downloads.
#
SUITE="http-dl"
load common
setup_file()
{
BUILD_DATE="${BUILD_DATE_1}"
create_pkg_buildinfo "preserve-1.0" \
"BUILD_DATE=${BUILD_DATE}" \
"CATEGORIES=download" \
"PKGPATH=download/preserve"
create_pkg_comment "preserve-1.0" "Package should remain at all times"
create_pkg_file "preserve-1.0" "share/doc/preserve"
create_pkg_preserve "preserve-1.0"
create_pkg "preserve-1.0"
#
# The packages are created normally, but our httpd knows to modify
# the downloads inflight depending on the filename requested. They
# only differ on the COMMENT.
#
for pkg in ok notfound mismatch truncate; do
create_pkg_buildinfo "download-${pkg}-1.0" \
"BUILD_DATE=${BUILD_DATE}" \
"CATEGORIES=download" \
"PKGPATH=download/download-${pkg}"
case "${pkg}" in
ok) c="Package tests download success" ;;
notfound) c="Package tests download failure (404)" ;;
mismatch) c="Package tests download failure (corrupt)" ;;
truncate) c="Package tests incorrect pkgin cache" ;;
esac
create_pkg_comment "download-${pkg}-1.0" "${c}"
create_pkg_file "download-${pkg}-1.0" \
"share/doc/download-${pkg}"
create_pkg "download-${pkg}-1.0"
done
create_pkg_summary
start_httpd
}
teardown_file()
{
stop_httpd
}
@test "${SUITE} perform initial pkgin setup" {
#
# Use pkg_add to aid pkgin-0.9 and also to keep the cache directory
# empty.
#
export PKG_PATH=${PACKAGES}/All
run pkg_add preserve
[ ${status} -eq 0 ]
run pkgin -fy update
[ ${status} -eq 0 ]
run rmdir ${PKGIN_CACHE}
[ ${status} -eq 0 ]
}
#
# Support for -4/-6 and passing -V down to libfetch were introduced in the
# same release. For now just ensure that -4 works and -6 (expected) fails.
#
@test "${SUITE} test IPv4/IPv6 flags" {
skip_if_version -lt 220900 "does not support -4 or -6"
# Supply arguments multiple times to verify we're not overflowing
# fetchflags.
run pkgin -444fVVVy update
[ ${status} -eq 0 ]
# socat is currently hardcoded to IPv4, this should fail.
run pkgin -666fVVVy update
[ ${status} -eq 1 ]
}
#
# Test a successful file download. Do not install.
#
@test "${SUITE} test download-only" {
run pkgin -dy install download-ok
[ ${status} -eq 0 ]
if [ ${PKGIN_VERSION} -lt 001101 -o ${PKGIN_VERSION} -eq 001600 ]; then
output_match "1 package.* to"
output_match ".*download-ok-1.0"
else
file_match "download-only.regex"
fi
run [ -f ${PKGIN_CACHE}/download-ok-1.0.tgz ]
[ ${status} -eq 0 ]
run pkg_info -qe download-ok
[ ${status} -eq 1 ]
}
#
# Now install separately.
#
@test "${SUITE} test install of already-downloaded package" {
run pkgin -y install download-ok
[ ${status} -eq 0 ]
if [ ${PKGIN_VERSION} -le 221000 ]; then
output_match "1 package.* to"
output_match ".*download-ok-1.0"
output_match "marking download-ok-1.0 as non auto-removable"
output_match_clean_pkg_install
else
file_match "install-downloaded.regex"
fi
run pkg_info -qe download-ok
[ ${status} -eq 0 ]
}
#
# Test pkgin clean, should result in an empty directory that can successfully
# be rmdir'd.
#
@test "${SUITE} test pkgin clean" {
run pkgin clean
[ ${status} -eq 0 ]
run rmdir ${PKGIN_CACHE}
[ ${status} -eq 0 ]
run [ ! -d ${PKGIN_CACHE} ]
[ ${status} -eq 0 ]
}
#
# Now install to test both the install and also the download counters.
#
@test "${SUITE} test download and install" {
run pkg_delete download-ok
[ ${status} -eq 0 ]
run pkgin -y install download-ok
[ ${status} -eq 0 ]
if [ ${PKGIN_VERSION} -le 221000 ]; then
output_match "1 package.* to .* install"
output_match "download-ok-1.0"
output_match "marking download-ok-1.0 as non auto-removable"
output_match_clean_pkg_install
else
file_match "download-install.regex"
fi
run pkg_info -qe download-ok
[ ${status} -eq 0 ]
}
#
# These tests all rely on our fake httpd to amend the packages in transit
# even though they exist fine in the repository.
#
@test "${SUITE} test failed download (not found)" {
run pkgin -y install download-notfound
[ ${status} -eq 1 ]
if [ ${PKGIN_VERSION} -lt 000900 ]; then
output_match "download-notfound-1.0 is not available"
# pkgin 0.9.4 doesn't print package name so just match on Not Found.
elif [ ${PKGIN_VERSION} -le 221000 ]; then
output_match "Not Found"
else
file_match "download-notfound.regex"
fi
run [ -L ${PKGIN_CACHE}/download-notfound-1.0.tgz ]
[ ${status} -eq 1 ]
}
@test "${SUITE} test failed download (truncated)" {
run pkgin -y install download-truncate
[ ${status} -eq 1 ]
if [ ${PKGIN_VERSION} -lt 000900 ]; then
output_match "truncated file"
elif [ ${PKGIN_VERSION} -lt 001000 ]; then
output_match "download-truncate-1.0 is not available"
elif [ ${PKGIN_VERSION} -le 221000 ]; then
output_match "download error: .* truncated"
output_match "downloading download-truncate-1.0.tgz done."
else
file_match "download-truncate.regex"
fi
run [ -L ${PKGIN_CACHE}/download-truncate-1.0.tgz ]
[ ${status} -eq 1 ]
}
@test "${SUITE} test failed download (mismatch)" {
run pkgin -y install download-mismatch
[ ${status} -eq 1 ]
if [ ${PKGIN_VERSION} -lt 000900 ]; then
output_match "pkg_install warnings: 0, errors: 1"
elif [ ${PKGIN_VERSION} -lt 001000 ]; then
output_match "pkgin.*: download mismatch"
elif [ ${PKGIN_VERSION} -le 221000 ]; then
output_match "download error: .* does not match pkg_summary"
output_match "downloading download-mismatch-1.0.tgz done."
else
file_match "download-mismatch.regex"
fi
run [ -L ${PKGIN_CACHE}/download-mismatch-1.0.tgz ]
[ ${status} -eq 1 ]
}
#
# Test again but all at the same time to verify counters and output format. As
# download-ok is still installed that exercises parts of the code that would be
# skipped if all downloads failed.
#
@test "${SUITE} test all failed downloads" {
run pkg_delete download-ok
[ ${status} -eq 0 ]
run pkgin -f update
[ ${status} -eq 0 ]
run pkgin -y install download-notfound download-truncate \
download-mismatch download-ok
[ ${status} -eq 1 ]
if [ ${PKGIN_VERSION} -lt 000900 ]; then
output_match "download-notfound-1.0 is not available"
output_match "truncated file"
elif [ ${PKGIN_VERSION} -lt 001000 ]; then
output_match "Not Found"
elif [ ${PKGIN_VERSION} -lt 001101 -o \
${PKGIN_VERSION} -eq 001600 ]; then
output_match "Not Found"
output_match "download error: .* truncated"
output_match "download error: .* does not match pkg_summary"
elif [ ${PKGIN_VERSION} -le 221000 ]; then
output_match "Not Found"
output_match "download error: .* truncated"
output_match "download error: .* does not match pkg_summary"
output_match "pkg_install warnings: 0, errors: 3"
else
file_match "download-all-failed.regex"
fi
}
#
# Verify everything is as it should be at the end of the tests.
#
# * pkgin 0.9.4 and earlier fail to install download-ok in the previous test.
# As this is the final test just ignore.
#
@test "${SUITE} compare pkg_info" {
skip_if_version -le 000904 "unsupported"
compare_pkg_info "pkg_info.final"
}