summaryrefslogtreecommitdiffstats
path: root/test/integration/test-snapshot
blob: 26ef5a7216f0627a0a1b716accf2fa2324495ebf (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
#!/bin/sh
set -e

TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"

setupenvironment
configarchitecture 'amd64'

buildsimplenativepackage 'awesome' 'native' '42' 'stable'
buildsimplenativepackage 'foo' 'all' '1.0' 'stable'
buildsimplenativepackage 'libbar' 'all' '1.0' 'stable'

getlabelfromsuite() { echo 'Testcases'; }
getoriginfromsuite() { echo 'Debian'; }
releasechanger() {
	# modifying the Release files in lists… bad stuff. Good that this is only a test…
	msgmsg "Changing $1 to $2"
	sed -i "s#^${1}: .*#${1}: ${2}#" $(find rootdir/var/lib/apt/lists -name '*Release')
	rm -f rootdir/var/cache/apt/*.bin
}


setupaptarchive --no-update
changetowebserver
testsuccess aptget update

testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris

testsuccessequal "'https://snapshot.debian.org/archive/debian/OPTIONNOTSET/dists/stable/InRelease' snapshot.debian.org_archive_debian_OPTIONNOTSET_dists_stable_InRelease 0 
'https://snapshot.debian.org/archive/debian/OPTIONNOTSET/dists/stable/main/source/Sources.xz' snapshot.debian.org_archive_debian_OPTIONNOTSET_dists_stable_main_source_Sources 0 
'https://snapshot.debian.org/archive/debian/OPTIONNOTSET/dists/stable/main/binary-amd64/Packages.xz' snapshot.debian.org_archive_debian_OPTIONNOTSET_dists_stable_main_binary-amd64_Packages 0 
'https://snapshot.debian.org/archive/debian/OPTIONNOTSET/dists/stable/main/binary-all/Packages.xz' snapshot.debian.org_archive_debian_OPTIONNOTSET_dists_stable_main_binary-all_Packages 0 
'https://snapshot.debian.org/archive/debian/OPTIONNOTSET/dists/stable/main/i18n/Translation-en.xz' snapshot.debian.org_archive_debian_OPTIONNOTSET_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris --snapshot OPTIONNOTSET

# repository does not support snapshots: we succeed here by silently ignoring the snapshot for the repository because it's not forced-on
releasechanger 'Origin' 'NoSnapshotsKnown'
testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris --snapshot OPTION-NOT-SET-AND-RELEASE-SAYS-NO


# Enable the snapshot feature
sed -i 's/http:/[snapshot=enable] http:/' rootdir/etc/apt/sources.list.d/*

# repository does not support snapshots: we fail here because now, we actually forced the feature enabled
testfailuremsg "E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable
E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable
E: The list of sources could not be read." aptget update --print-uris -S OPTION-SET-AND-RELEASE-SAYS-NO

releasechanger 'Origin' 'Debian'
testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris

for option in -S --snapshot; do
testsuccessequal "'https://snapshot.debian.org/archive/debian/BANANA/dists/stable/InRelease' snapshot.debian.org_archive_debian_BANANA_dists_stable_InRelease 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/stable/main/source/Sources.xz' snapshot.debian.org_archive_debian_BANANA_dists_stable_main_source_Sources 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/stable/main/binary-amd64/Packages.xz' snapshot.debian.org_archive_debian_BANANA_dists_stable_main_binary-amd64_Packages 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/stable/main/binary-all/Packages.xz' snapshot.debian.org_archive_debian_BANANA_dists_stable_main_binary-all_Packages 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/stable/main/i18n/Translation-en.xz' snapshot.debian.org_archive_debian_BANANA_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris $option BANANA
done


# Let us update for realz
mkdir aptarchive/snapshot/BANANA -p
cp -a aptarchive/dists aptarchive/snapshot/BANANA

testsuccessequal "Hit:1 http://localhost:${APTHTTPPORT} stable InRelease
Get:2 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable InRelease [$(stat -c %s aptarchive/dists/stable/InRelease) B]
Get:3 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable/main Sources [$(stat -c %s aptarchive/dists/stable/main/source/Sources.gz) B]
Get:4 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable/main amd64 Packages [$(stat -c %s aptarchive/dists/stable/main/binary-amd64/Packages.gz) B]
Get:5 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable/main all Packages [$(stat -c %s aptarchive/dists/stable/main/binary-all/Packages.gz) B]
Get:6 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable/main Translation-en [$(stat -c %s aptarchive/dists/stable/main/i18n/Translation-en.gz) B]
Reading package lists..." \
	aptget update  -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/" -SBANANA

msgmsg "Cache constructed without snapshot"
testsuccessequal "Package files:
 500 http://localhost:${APTHTTPPORT} stable/main all Packages
     release o=Debian,a=stable,n=stable,l=Testcases,c=main,b=all
     origin localhost
 500 http://localhost:${APTHTTPPORT} stable/main amd64 Packages
     release o=Debian,a=stable,n=stable,l=Testcases,c=main,b=amd64
     origin localhost
Pinned packages:" \
	aptcache policy  -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/" 

testsuccessequal "'http://localhost:${APTHTTPPORT}/pool/awesome_42_amd64.deb' awesome_42_amd64.deb $(stat -c %s aptarchive/pool/awesome_42_amd64.deb) " \
	aptget install --print-uris -qq awesome

msgmsg "Cache constructed with snapshot"
testsuccessequal "Package files:
 500 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable/main all Packages
     release o=Debian,a=stable,n=stable,l=Testcases,c=main,b=all
     origin localhost
 500 http://localhost:${APTHTTPPORT}/snapshot/BANANA stable/main amd64 Packages
     release o=Debian,a=stable,n=stable,l=Testcases,c=main,b=amd64
     origin localhost
Pinned packages:" \
	aptcache policy  -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/" -SBANANA

testsuccessequal "'http://localhost:${APTHTTPPORT}/snapshot/BANANA/pool/awesome_42_amd64.deb' awesome_42_amd64.deb $(stat -c %s aptarchive/pool/awesome_42_amd64.deb) " \
	aptget install --print-uris -qq awesome  -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/" -SBANANA


msgmsg "Origin: Ubuntu"
releasechanger 'Origin' 'Ubuntu'
testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/source/Sources.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_source_Sources 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris $option BANANA

msgmsg "Label: Debian"
releasechanger 'Label' 'Debian'
testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/source/Sources.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_source_Sources 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/stable/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris $option BANANA

testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/InRelease' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris -o Acquire::Snapshots::URI::Label::Debian="http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/" -SBANANA

msgmsg "Origin: Unknown"
releasechanger 'Origin' 'Unknown'
# XXX: @PATH@ is empty here so we have //, there isn't much we can do here, people don't have to use @PATH@ of course.
testsuccessequal "'https://example.org/snapshots//BANANA/dists/stable/InRelease' example.org_snapshots__BANANA_dists_stable_InRelease 0 
'https://example.org/snapshots//BANANA/dists/stable/main/source/Sources.xz' example.org_snapshots__BANANA_dists_stable_main_source_Sources 0 
'https://example.org/snapshots//BANANA/dists/stable/main/binary-amd64/Packages.xz' example.org_snapshots__BANANA_dists_stable_main_binary-amd64_Packages 0 
'https://example.org/snapshots//BANANA/dists/stable/main/binary-all/Packages.xz' example.org_snapshots__BANANA_dists_stable_main_binary-all_Packages 0 
'https://example.org/snapshots//BANANA/dists/stable/main/i18n/Translation-en.xz' example.org_snapshots__BANANA_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris $option BANANA -o Acquire::Snapshots::URI::Host::localhost="https://example.org/snapshots/@PATH@/@SNAPSHOTID@/"

msgmsg "Snapshots: set in the InRelease file"
sed -i '/^Origin: / a\
Snapshots: https://example.org/snapshots/@SNAPSHOTID@/' $(find rootdir/var/lib/apt/lists -name '*Release')
rm -f rootdir/var/cache/apt/*.bin

testsuccessequal "'https://example.org/snapshots/BANANA/dists/stable/InRelease' example.org_snapshots_BANANA_dists_stable_InRelease 0 
'https://example.org/snapshots/BANANA/dists/stable/main/source/Sources.xz' example.org_snapshots_BANANA_dists_stable_main_source_Sources 0 
'https://example.org/snapshots/BANANA/dists/stable/main/binary-amd64/Packages.xz' example.org_snapshots_BANANA_dists_stable_main_binary-amd64_Packages 0 
'https://example.org/snapshots/BANANA/dists/stable/main/binary-all/Packages.xz' example.org_snapshots_BANANA_dists_stable_main_binary-all_Packages 0 
'https://example.org/snapshots/BANANA/dists/stable/main/i18n/Translation-en.xz' example.org_snapshots_BANANA_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris -SBANANA

releasechanger 'Snapshots' 'no'
testfailuremsg "E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable
E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable
E: The list of sources could not be read." aptget update --print-uris -S BANANA

testfailuremsg "E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable
E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable
E: The list of sources could not be read." aptget update --print-uris -S BANANA -o Acquire::Snapshots::URI::Host::localhost="https://example.org/snapshots/@PATH@/@SNAPSHOTID@/"

msgmsg "Snapshot URI configured in apt.conf"
sed -i '/^Snapshots: / d' $(find rootdir/var/lib/apt/lists -name '*Release')
releasechanger 'Label' 'Testcases'

echo "Acquire::Snapshots::URI::Label::Testcases \"http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/\";" > rootdir/etc/apt/apt.conf.d/changelog.conf
testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/InRelease' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_InRelease 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_source_Sources 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_binary-amd64_Packages 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_binary-all_Packages 0 
'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris -SBANANA

rm rootdir/etc/apt/apt.conf.d/changelog.conf

msgmsg "Testing host-based seed: Ubuntu"

echo "deb http://security.ubuntu.com/ubuntu/ mantic-security main" > rootdir/etc/apt/security.list
testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_i18n_Translation-en 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/InRelease' security.ubuntu.com_ubuntu_dists_mantic-security_InRelease 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/binary-amd64/Packages.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_binary-amd64_Packages 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/binary-all/Packages.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_binary-all_Packages 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/i18n/Translation-en.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=security.list -o Dir::Etc::SourceParts=/dev/null -SBANANA

echo "deb [snapshot=BANANA] http://security.ubuntu.com/ubuntu/ mantic-security main" > rootdir/etc/apt/security.list
testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_i18n_Translation-en 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/InRelease' security.ubuntu.com_ubuntu_dists_mantic-security_InRelease 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/binary-amd64/Packages.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_binary-amd64_Packages 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/binary-all/Packages.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_binary-all_Packages 0 
'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/i18n/Translation-en.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=security.list -o Dir::Etc::SourceParts=/dev/null
echo "deb [snapshot=BANANA] http://archive.ubuntu.com/ubuntu/ mantic main" > rootdir/etc/apt/archive.list
testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/InRelease' archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=archive.list -o Dir::Etc::SourceParts=/dev/null
echo "deb [snapshot=BANANA] http://cc.archive.ubuntu.com/ubuntu/ mantic main" > rootdir/etc/apt/cc.archive.list
testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/InRelease' cc.archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=cc.archive.list -o Dir::Etc::SourceParts=/dev/null

# with a custom override for .archive.ubuntu.com
testsuccessequal "'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 
'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 
'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 
'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/InRelease' cc.archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 
'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=cc.archive.list -o Dir::Etc::SourceParts=/dev/null -o "Acquire::Snapshots::URI::Host::.archive.ubuntu.com"="https://cc.snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"

testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 
'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/InRelease' archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 
'http://archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=archive.list -o Dir::Etc::SourceParts=/dev/null -o "Acquire::Snapshots::URI::Host::.archive.ubuntu.com"="https://cc.snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"

testfailureequal "E: Snapshots not supported for http://archive.ubuntu.com/ubuntu/ mantic
E: The list of sources could not be read." aptget update --print-uris -o Dir::Etc::SourceList=archive.list -o Dir::Etc::SourceParts=/dev/null -o "Acquire::Snapshots::URI::Host::archive.ubuntu.com"="no"

msgmsg "Testing host based-seeds: PPA"

echo "deb [snapshot=BANANA] http://ppa.launchpad.net/owner/archive/distribution/ mantic main" > rootdir/etc/apt/ppa.list
testsuccessequal "'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/InRelease' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_InRelease 0 
'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-amd64_Packages 0 
'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-all_Packages 0 
'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_i18n_Translation-en 0 
'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/InRelease' ppa.launchpad.net_owner_archive_distribution_dists_mantic_InRelease 0 
'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/main/binary-amd64/Packages.xz' ppa.launchpad.net_owner_archive_distribution_dists_mantic_main_binary-amd64_Packages 0 
'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/main/binary-all/Packages.xz' ppa.launchpad.net_owner_archive_distribution_dists_mantic_main_binary-all_Packages 0 
'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/main/i18n/Translation-en.xz' ppa.launchpad.net_owner_archive_distribution_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=ppa.list -o Dir::Etc::SourceParts=/dev/null

echo "deb [snapshot=BANANA] http://ppa.launchpadcontent.net/owner/archive/distribution/ mantic main" > rootdir/etc/apt/ppa.list
testsuccessequal "'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/InRelease' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_InRelease 0 
'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-amd64_Packages 0 
'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-all_Packages 0 
'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_i18n_Translation-en 0 
'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/InRelease' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_InRelease 0 
'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/main/binary-amd64/Packages.xz' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_main_binary-amd64_Packages 0 
'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/main/binary-all/Packages.xz' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_main_binary-all_Packages 0 
'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/main/i18n/Translation-en.xz' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=ppa.list -o Dir::Etc::SourceParts=/dev/null

msgmsg "Testing host based-seeds: Debian"

echo "deb [snapshot=BANANA] http://deb.debian.org/debian/ unstable main" > rootdir/etc/apt/debian.list
testsuccessequal "'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/InRelease' snapshot.debian.org_archive_debian_BANANA_dists_unstable_InRelease 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/main/binary-amd64/Packages.xz' snapshot.debian.org_archive_debian_BANANA_dists_unstable_main_binary-amd64_Packages 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/main/binary-all/Packages.xz' snapshot.debian.org_archive_debian_BANANA_dists_unstable_main_binary-all_Packages 0 
'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/main/i18n/Translation-en.xz' snapshot.debian.org_archive_debian_BANANA_dists_unstable_main_i18n_Translation-en 0 
'http://deb.debian.org/debian/dists/unstable/InRelease' deb.debian.org_debian_dists_unstable_InRelease 0 
'http://deb.debian.org/debian/dists/unstable/main/binary-amd64/Packages.xz' deb.debian.org_debian_dists_unstable_main_binary-amd64_Packages 0 
'http://deb.debian.org/debian/dists/unstable/main/binary-all/Packages.xz' deb.debian.org_debian_dists_unstable_main_binary-all_Packages 0 
'http://deb.debian.org/debian/dists/unstable/main/i18n/Translation-en.xz' deb.debian.org_debian_dists_unstable_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=debian.list -o Dir::Etc::SourceParts=/dev/null

echo "deb [snapshot=BANANA] http://deb.debian.org/debian-security/ stable-security main" > rootdir/etc/apt/debian-security.list
testsuccessequal "'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/InRelease' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_InRelease 0 
'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/main/binary-amd64/Packages.xz' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_main_binary-amd64_Packages 0 
'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/main/binary-all/Packages.xz' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_main_binary-all_Packages 0 
'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/main/i18n/Translation-en.xz' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_main_i18n_Translation-en 0 
'http://deb.debian.org/debian-security/dists/stable-security/InRelease' deb.debian.org_debian-security_dists_stable-security_InRelease 0 
'http://deb.debian.org/debian-security/dists/stable-security/main/binary-amd64/Packages.xz' deb.debian.org_debian-security_dists_stable-security_main_binary-amd64_Packages 0 
'http://deb.debian.org/debian-security/dists/stable-security/main/binary-all/Packages.xz' deb.debian.org_debian-security_dists_stable-security_main_binary-all_Packages 0 
'http://deb.debian.org/debian-security/dists/stable-security/main/i18n/Translation-en.xz' deb.debian.org_debian-security_dists_stable-security_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=debian-security.list -o Dir::Etc::SourceParts=/dev/null

exit 0
msgmsg "Failure cases"

# no @CHANGEPATH@ in the URI
testequal 'E: Failed to fetch changelog:/foo.changelog  Changelog unavailable for foo=1.0' \
	aptget update  -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/snapshot" -SBANANA

testequal "E: Failed to fetch http://localhost:${APTHTTPPORT}/does/not/exist/main/f/foo/foo_1.0/change.txt  Changelog unavailable for foo=1.0 (404  Not Found)" \
	aptget update -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/does/not/exist/@SNAPSHOTID@" -SBANANA