summaryrefslogtreecommitdiffstats
path: root/tests/morgue.test
blob: a302ec2e7838381736bdeee93f29d8757787d339 (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
set -u
. "$TESTSDIR"/test.inc

mkdir conf
cat > conf/options <<EOF
morguedir ./morgue
export silent-never
EOF
cat > conf/distributions <<EOF
Codename: test
Architectures: source
Components: main
EOF
cat > fake.dsc <<EOF
Format: 1.0
Source: bla
Binary: bla
Architecture: all
Section: whatever
Priority: important
Version: 1.7
Maintainer: nobody <nobody@localhost>
Files:
EOF


testrun - -C main includedsc test fake.dsc 3<<EOF
stdout
$(odb)
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
$(ofa 'pool/main/b/bla/bla_1.7.dsc')
$(opa 'bla' unset 'test' 'main' 'source' 'dsc')
EOF

testrun - remove test bla 3<<EOF
stdout
$(opd 'bla' unset test main source dsc)
-v0*=Deleting files no longer referenced...
-v2*=Created directory "./morgue"
-v2*=removed now empty directory ./pool/main/b/bla
-v2*=removed now empty directory ./pool/main/b
-v2*=removed now empty directory ./pool/main
-v2*=removed now empty directory ./pool
$(ofd 'pool/main/b/bla/bla_1.7.dsc')
EOF

ls -la morgue
dodo test -f morgue/bla_1.7.dsc
dodo test ! -e pool

rm -r morgue
# test what happens if one cannot write there:
mkdir morgue
chmod a-w morgue

testrun - -C main includedsc test fake.dsc 3<<EOF
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
$(ofa 'pool/main/b/bla/bla_1.7.dsc')
$(opa 'bla' unset 'test' 'main' 'source' 'dsc')
EOF

testrun - remove test bla 3<<EOF
stdout
$(opd 'bla' unset test main source dsc)
-v0*=Deleting files no longer referenced...
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
stderr
*=error 13 creating morgue-file ./morgue/bla_1.7.dsc: Permission denied
-v0*=There have been errors!
returns 243
EOF

find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
EOF
dodiff results.expected results

# if it could not be moved to the morgue, it should stay in the pool:
testrun - dumpunreferenced 3<<EOF
stdout
*=pool/main/b/bla/bla_1.7.dsc
EOF

# and deleting it there of course fails again:
testrun - deleteunreferenced 3<<EOF
stdout
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
stderr
*=error 13 creating morgue-file ./morgue/bla_1.7.dsc: Permission denied
-v0*=There have been errors!
returns 243
EOF

# if it could not be moved to the morgue, it should stay in the pool:
testrun - dumpunreferenced 3<<EOF
stdout
*=pool/main/b/bla/bla_1.7.dsc
EOF

chmod u+w morgue

# now it should work:
testrun - deleteunreferenced 3<<EOF
stdout
-v2*=removed now empty directory ./pool/main/b/bla
-v2*=removed now empty directory ./pool/main/b
-v2*=removed now empty directory ./pool/main
-v2*=removed now empty directory ./pool
$(ofd 'pool/main/b/bla/bla_1.7.dsc')
EOF
find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
morgue/bla_1.7.dsc
EOF
dodiff results.expected results
# and be gone:
testrun empty dumpunreferenced



ls -la morgue
dodo test -f morgue/bla_1.7.dsc
dodo test ! -e pool

# Next test: what if the file is missing?

testrun - -C main includedsc test fake.dsc 3<<EOF
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
$(ofa 'pool/main/b/bla/bla_1.7.dsc')
$(opa 'bla' unset 'test' 'main' 'source' 'dsc')
EOF

dodo rm pool/main/b/bla/bla_1.7.dsc

testrun - remove test bla 3<<EOF
stdout
$(opd 'bla' unset test main source dsc)
-v0*=Deleting files no longer referenced...
stderr
*=./pool/main/b/bla/bla_1.7.dsc not found, forgetting anyway
stdout
$(ofd 'pool/main/b/bla/bla_1.7.dsc')
EOF

find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
morgue/bla_1.7.dsc
EOF
dodiff results.expected results

# Next test: file cannot be moved

testrun - -C main includedsc test fake.dsc 3<<EOF
stdout
$(ofa 'pool/main/b/bla/bla_1.7.dsc')
$(opa 'bla' unset 'test' 'main' 'source' 'dsc')
EOF

dodo chmod a-w pool/main/b/bla

testrun - remove test bla 3<<EOF
stdout
$(opd 'bla' unset test main source dsc)
-v0*=Deleting files no longer referenced...
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
stderr
*=error 13 while unlinking ./pool/main/b/bla/bla_1.7.dsc: Permission denied
-v0*=There have been errors!
returns 243
EOF

dodo chmod u+w pool/main/b/bla

find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
morgue/bla_1.7.dsc
EOF
dodiff results.expected results
testrun - dumpunreferenced 3<<EOF
stdout
*=pool/main/b/bla/bla_1.7.dsc
EOF

# now it should work:
testrun - deleteunreferenced 3<<EOF
stdout
-v2*=removed now empty directory ./pool/main/b/bla
-v2*=removed now empty directory ./pool/main/b
-v2*=removed now empty directory ./pool/main
-v2*=removed now empty directory ./pool
$(ofd 'pool/main/b/bla/bla_1.7.dsc')
EOF
find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
morgue/bla_1.7.dsc
morgue/bla_1.7.dsc-1
EOF
dodiff results.expected results
# and be gone:
testrun empty dumpunreferenced

# Test symbolic link:
testrun - -C main includedsc test fake.dsc 3<<EOF
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
$(ofa 'pool/main/b/bla/bla_1.7.dsc')
$(opa 'bla' unset 'test' 'main' 'source' 'dsc')
EOF

dodo mv pool/main/b/bla/bla_1.7.dsc pool/main/b/bla/bla_1.7.dscc
dodo ln -s bla_1.7.dscc pool/main/b/bla/bla_1.7.dsc

testrun - remove test bla 3<<EOF
stdout
$(opd 'bla' unset test main source dsc)
-v0*=Deleting files no longer referenced...
$(ofd 'pool/main/b/bla/bla_1.7.dsc')
EOF

ls -l morgue
find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
morgue/bla_1.7.dsc
morgue/bla_1.7.dsc-1
EOF
dodiff results.expected results

dodo mv pool/main/b/bla/bla_1.7.dscc pool/main/b/bla/bla_1.7.dsc
testrun - _detect pool/main/b/bla/bla_1.7.dsc 3<<EOF
stdout
$(ofa 'pool/main/b/bla/bla_1.7.dsc')
-v0*=1 files were added but not used.
-v0*=The next deleteunreferenced call will delete them.
EOF

dodo chmod a-r pool/main/b/bla/bla_1.7.dsc
testrun - deleteunreferenced 3<<EOF
stdout
$(ofd 'pool/main/b/bla/bla_1.7.dsc')
-v2*=removed now empty directory ./pool/main/b/bla
-v2*=removed now empty directory ./pool/main/b
-v2*=removed now empty directory ./pool/main
-v2*=removed now empty directory ./pool
EOF
ls -l morgue
find morgue -mindepth 1 | sort > results
cat > results.expected <<EOF
morgue/bla_1.7.dsc
morgue/bla_1.7.dsc-1
morgue/bla_1.7.dsc-2
EOF
dodiff results.expected results

# TODO: is there a way to check if failing copying is handled correctly?
# that needs a file not readable, not renameable to morgue, but can be unlinked...

# TODO: check if things like a failed include work correctly
# (they should only copy things to the morgue that were in the pool previously)

dodo test ! -e pool
rm -r db morgue fake.dsc conf results results.expected
testsuccess