summaryrefslogtreecommitdiffstats
path: root/tests/multiversion.sh
blob: a7b83ee152f0f651251cda629ff0e69e929d4f01 (plain)
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/sh
set -u

# Copyright (C) 2017, Benjamin Drung <benjamin.drung@profitbricks.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

. "${0%/*}/shunit2-helper-functions.sh"

oneTimeSetUp() {
	for revision in 1 2 2+deb8u1 10; do
		mkdir -p "$PKGS"
		(cd $PKGS && PACKAGE=hello SECTION=main DISTRI=buster EPOCH="" VERSION=2.9 REVISION=-$revision ../genpackage.sh)
	done
}

setUp() {
	create_repo
	echo "Limit: -1" >> $REPO/conf/distributions
}

tearDown() {
	check_db
}

four_hellos() {
	for revision in 1 2 2+deb8u1 10; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb
	done
}

test_ls() {
	(cd $PKGS && PACKAGE=kvm SECTION=main DISTRI=buster VERSION=1.2.1 REVISION=-8 ../genpackage.sh)
	(cd $PKGS && PACKAGE=kvm SECTION=main DISTRI=buster VERSION=1.2.1 REVISION=-9 ../genpackage.sh)
	(cd $PKGS && PACKAGE=appdirs SECTION=main DISTRI=buster VERSION=1.3.0 REVISION=-1 ../genpackage.sh)
	for package in hello_2.9-1 kvm_1.2.1-8 kvm_1.2.1-9 appdirs_1.3.0-1; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/${package}_${ARCH}.deb
	done
	assertEquals "\
kvm | 1.2.1-9 | buster | $ARCH
kvm | 1.2.1-8 | buster | $ARCH" "$($REPREPRO -b $REPO ls kvm)"
	assertEquals "\
buster|main|$ARCH: kvm 1.2.1-9
buster|main|$ARCH: kvm 1.2.1-8" "$($REPREPRO -b $REPO list buster kvm)"
}

test_sorting() {
	four_hellos
	assertEquals "\
buster|main|$ARCH: hello 2.9-10
buster|main|$ARCH: hello 2.9-2+deb8u1
buster|main|$ARCH: hello 2.9-2
buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	assertEquals "\
hello |       2.9-10 | buster | $ARCH
hello | 2.9-2+deb8u1 | buster | $ARCH
hello |        2.9-2 | buster | $ARCH
hello |        2.9-1 | buster | $ARCH" "$($REPREPRO -b $REPO ls hello)"
}

test_include_twice() {
	for revision in 1 2; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb
	done
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-1_${ARCH}.deb
	assertEquals "\
hello | 2.9-2 | buster | $ARCH
hello | 2.9-1 | buster | $ARCH" "$($REPREPRO -b $REPO ls hello)"
}

test_copy_latest() {
	four_hellos
	add_distro bullseye "Limit: -1"
	call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello hello
	assertEquals "bullseye|main|$ARCH: hello 2.9-10" "$($REPREPRO -b $REPO list bullseye)"
}

test_copy_specific() {
	four_hellos
	add_distro bullseye "Limit: -1"
	call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello=2.9-10 hello=2.9-1 hello=2.9-10
	assertEquals "\
bullseye|main|$ARCH: hello 2.9-10
bullseye|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list bullseye)"
}

test_remove_latest() {
	four_hellos
	add_distro bullseye "Limit: -1"
	call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster hello=2.9-10 hello=2.9-1 hello=2.9-10
	call $REPREPRO $VERBOSE_ARGS -b $REPO remove bullseye hello
	assertEquals "\
hello |       2.9-10 |   buster | $ARCH
hello | 2.9-2+deb8u1 |   buster | $ARCH
hello |        2.9-2 |   buster | $ARCH
hello |        2.9-1 |   buster | $ARCH
hello |        2.9-1 | bullseye | $ARCH" "$($REPREPRO -b $REPO ls hello)"
}

test_remove_specific() {
	four_hellos
	call $REPREPRO $VERBOSE_ARGS -b $REPO remove buster hello=2.9-2+deb8u1 hellox hello=2.9-2+deb8u1
	assertEquals "\
buster|main|$ARCH: hello 2.9-10
buster|main|$ARCH: hello 2.9-2
buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
}

test_removefilter() {
	(cd $PKGS && PACKAGE=kvm SECTION=main DISTRI=buster VERSION=1.2.1 REVISION=-8 ../genpackage.sh)
	(cd $PKGS && PACKAGE=kvm SECTION=main DISTRI=buster VERSION=1.2.1 REVISION=-9 ../genpackage.sh)
	for package in hello_2.9-1 kvm_1.2.1-8 kvm_1.2.1-9; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/${package}_${ARCH}.deb
	done
	assertEquals "\
buster|main|$ARCH: hello 2.9-1
buster|main|$ARCH: kvm 1.2.1-9
buster|main|$ARCH: kvm 1.2.1-8" "$($REPREPRO -b $REPO list buster)"

	add_distro bullseye "Limit: -1"
	call $REPREPRO $VERBOSE_ARGS -b $REPO copy bullseye buster kvm
	assertEquals "bullseye|main|$ARCH: kvm 1.2.1-9" "$($REPREPRO -b $REPO list bullseye)"

	call $REPREPRO $VERBOSE_ARGS -b $REPO removefilter buster "Package (= kvm)"
	assertEquals "buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	assertTrue "kvm_1.2.1-8_$ARCH.deb is still in the pool!" "test ! -e $REPO/pool/main/k/kvm/kvm_1.2.1-8_$ARCH.deb"
	assertTrue "kvm_1.2.1-9_$ARCH.deb is missing from the pool!" "test -e $REPO/pool/main/k/kvm/kvm_1.2.1-9_$ARCH.deb"

	call $REPREPRO $VERBOSE_ARGS -b $REPO removefilter bullseye "Package (= kvm)"
	assertEquals "buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	assertTrue "kvm_1.2.1-9_$ARCH.deb is still in the pool!" "test ! -e $REPO/pool/main/k/kvm/kvm_1.2.1-9_$ARCH.deb"
}

test_readd_distribution() {
	# Test case for https://github.com/profitbricks/reprepro/issues/1
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-1_${ARCH}.deb

	# Add distribution
	cp $REPO/conf/distributions $REPO/conf/distributions.backup
	add_distro bullseye "Limit: -1"
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb bullseye $PKGS/hello_2.9-2_${ARCH}.deb

	# Remove distribution
	mv $REPO/conf/distributions.backup $REPO/conf/distributions
	call $REPREPRO $VERBOSE_ARGS -b $REPO --delete clearvanished

	# Re-add distribution again
	echo "I: Re-adding bullseye..."
	add_distro bullseye "Limit: -1"
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb bullseye $PKGS/hello_2.9-10_${ARCH}.deb
	assertEquals "bullseye|main|$ARCH: hello 2.9-10" "$($REPREPRO -b $REPO list bullseye)"
}

test_limit3() {
	sed -i 's/^Limit: .*$/Limit: 3/' $REPO/conf/distributions
	for revision in 1 2 2+deb8u1; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb
	done
	assertEquals "\
buster|main|${ARCH}: hello 2.9-2+deb8u1
buster|main|${ARCH}: hello 2.9-2
buster|main|${ARCH}: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-10_${ARCH}.deb
	assertEquals "\
buster|main|${ARCH}: hello 2.9-10
buster|main|${ARCH}: hello 2.9-2+deb8u1
buster|main|${ARCH}: hello 2.9-2" "$($REPREPRO -b $REPO list buster)"
}

test_reduce_limit() {
	for revision in 1 2 2+deb8u1; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb
	done
	assertEquals "\
buster|main|${ARCH}: hello 2.9-2+deb8u1
buster|main|${ARCH}: hello 2.9-2
buster|main|${ARCH}: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	sed -i 's/^Limit: .*$/Limit: 1/' $REPO/conf/distributions
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-10_${ARCH}.deb
	assertEquals "buster|main|${ARCH}: hello 2.9-10" "$($REPREPRO -b $REPO list buster)"
	assertEquals "\
Distribution: buster
Source: hello
Version: 2.9-10
Files:
 pool/main/h/hello/hello_2.9-10_$ARCH.deb b 1" "$($REPREPRO -b $REPO dumptracks)"
}

test_reduce_limit_archive() {
	clear_distro
	add_distro buster-archive "Limit: 7"
	add_distro buster "Limit: -1\nArchive: buster-archive"
	for revision in 1 2; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb
	done
	assertEquals "\
buster|main|${ARCH}: hello 2.9-2
buster|main|${ARCH}: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	sed -i 's/^Limit: -1$/Limit: 1/' $REPO/conf/distributions
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-10_${ARCH}.deb
	assertEquals "\
hello |  2.9-2 | buster-archive | $ARCH
hello |  2.9-1 | buster-archive | $ARCH
hello | 2.9-10 |         buster | $ARCH" "$($REPREPRO -b $REPO ls hello)"
	assertEquals "\
Distribution: buster-archive
Source: hello
Version: 2.9-1
Files:
 pool/main/h/hello/hello_2.9-1_$ARCH.deb b 1

Distribution: buster-archive
Source: hello
Version: 2.9-2
Files:
 pool/main/h/hello/hello_2.9-2_$ARCH.deb b 1

Distribution: buster
Source: hello
Version: 2.9-10
Files:
 pool/main/h/hello/hello_2.9-10_$ARCH.deb b 1" "$($REPREPRO -b $REPO dumptracks)"
}

test_limit_old() {
	for revision in 1 2 10; do
		call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-${revision}_${ARCH}.deb
	done
	assertEquals "\
buster|main|${ARCH}: hello 2.9-10
buster|main|${ARCH}: hello 2.9-2
buster|main|${ARCH}: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	sed -i 's/^Limit: .*$/Limit: 2/' $REPO/conf/distributions
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb buster $PKGS/hello_2.9-2+deb8u1_${ARCH}.deb
	assertEquals "\
buster|main|${ARCH}: hello 2.9-10
buster|main|${ARCH}: hello 2.9-2+deb8u1" "$($REPREPRO -b $REPO list buster)"
}

test_update_packages() {
	# Test case for https://github.com/profitbricks/reprepro/issues/6
	local upstream_repo
	upstream_repo="${0%/*}/upstreamrepo"

	four_hellos
	rm -rf "$upstream_repo"
	mv "$REPO" "$upstream_repo"

	mkdir -p "$REPO/conf"
	cat > "$REPO/conf/distributions" <<EOF
Origin: Icinga2
Label: Icinga2
Suite: icinga-stretch
Codename: icinga-stretch
Description: Icinga2 packages for Debian Stretch
Architectures: $ARCH
Components: main
Update: icinga-stretch
Log: icinga2.log
Limit: -1
EOF
	cat > "$REPO/conf/updates" <<EOF
Name: icinga-stretch
Method: file://$(readlink -f $upstream_repo)
Suite: buster
Components: main
Architectures: $ARCH
VerifyRelease: blindtrust
GetInRelease: no
EOF
	call $REPREPRO $VERBOSE_ARGS -b $REPO --noskipold update
	assertEquals "icinga-stretch|main|$ARCH: hello 2.9-10" "$($REPREPRO -b $REPO list icinga-stretch)"

	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedeb icinga-stretch $PKGS/hello_2.9-2_${ARCH}.deb
	call $REPREPRO $VERBOSE_ARGS -b $REPO --noskipold update
	assertEquals "\
icinga-stretch|main|$ARCH: hello 2.9-10
icinga-stretch|main|$ARCH: hello 2.9-2" "$($REPREPRO -b $REPO list icinga-stretch)"
}

test_includedsc_sources() {
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedsc buster $PKGS/hello_2.9-1.dsc
	call $REPREPRO $VERBOSE_ARGS -b $REPO -C main includedsc buster $PKGS/hello_2.9-2.dsc
	assertEquals "\
buster|main|source: hello 2.9-2
buster|main|source: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"

	call $REPREPRO $VERBOSE_ARGS -b $REPO removesrc buster hello 2.9-1
	assertEquals "buster|main|source: hello 2.9-2" "$($REPREPRO -b $REPO list buster)"
}

test_database_upgrade() {
	# Test case for https://github.com/profitbricks/reprepro/issues/8
	rm -rf "$REPO"
	cp -r "${0%/*}/old-database" "$REPO"
	call $REPREPRO $VERBOSE_ARGS -b $REPO export
	assertEquals "\
bullseye|main|amd64
bullseye|main|i386
bullseye|main|source
bullseye|non-free|amd64
bullseye|non-free|i386
bullseye|non-free|source" "$(db_dump "$REPO/db/packages.db" | sed -n 's/^database=//p')"
}

test_move_specific() {
	four_hellos
	add_distro bullseye
	$REPREPRO -b $REPO export bullseye
	call $REPREPRO $VERBOSE_ARGS -b $REPO move bullseye buster hello=2.9-2
	assertEquals "\
buster|main|$ARCH: hello 2.9-10
buster|main|$ARCH: hello 2.9-2+deb8u1
buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	assertEquals "bullseye|main|$ARCH: hello 2.9-2" "$($REPREPRO -b $REPO list bullseye)"
}

test_movesrc_specific() {
	four_hellos
	add_distro bullseye
	$REPREPRO -b $REPO export bullseye
	call $REPREPRO $VERBOSE_ARGS -b $REPO movesrc bullseye buster hello 2.9-2
	assertEquals "\
buster|main|$ARCH: hello 2.9-10
buster|main|$ARCH: hello 2.9-2+deb8u1
buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	assertEquals "bullseye|main|$ARCH: hello 2.9-2" "$($REPREPRO -b $REPO list bullseye)"
}

test_movefilter_specific() {
	four_hellos
	add_distro bullseye "Limit: -1"
	$REPREPRO -b $REPO export bullseye
	call $REPREPRO $VERBOSE_ARGS -b $REPO movefilter bullseye buster 'Package (= hello), $Version (>> 2.9-2)'
	assertEquals "\
buster|main|$ARCH: hello 2.9-2
buster|main|$ARCH: hello 2.9-1" "$($REPREPRO -b $REPO list buster)"
	assertEquals "\
bullseye|main|$ARCH: hello 2.9-10
bullseye|main|$ARCH: hello 2.9-2+deb8u1" "$($REPREPRO -b $REPO list bullseye)"
}

. shunit2