testmorgue.sh 9.63 KB
Newer Older
Bernhard Link's avatar
Bernhard Link committed
1 2 3 4 5 6 7 8 9
#!/bin/bash

set -e
if [ "x$TESTINCSETUP" != "xissetup" ] ; then
	source $(dirname $0)/test.inc
fi

mkdir conf
cat > conf/options <<EOF
10
morguedir ./morgue
Bernhard Link's avatar
Bernhard Link committed
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
export 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
stderr
=Data seems not to be signed trying to use directly...
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
-v2*=Created directory "./db"
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' added to checksums.db(pool).
-d1*=db: 'bla' added to packages.db(test|main|source).
EOF

testrun - remove test bla 3<<EOF
stderr
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v1*=removing 'bla' from 'test|main|source'...
-d1*=db: 'bla' removed from packages.db(test|main|source).
-v0*=Deleting files no longer referenced...
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
55
-v2*=Created directory "./morgue"
Bernhard Link's avatar
Bernhard Link committed
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
-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
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' removed from checksums.db(pool).
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
stderr
=Data seems not to be signed trying to use directly...
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' added to checksums.db(pool).
-d1*=db: 'bla' added to packages.db(test|main|source).
EOF

testrun - remove test bla 3<<EOF
stderr
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v1*=removing 'bla' from 'test|main|source'...
-d1*=db: 'bla' removed from packages.db(test|main|source).
-v0*=Deleting files no longer referenced...
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
stderr
96
*=error 13 creating morgue-file ./morgue/bla_1.7.dsc: Permission denied
Bernhard Link's avatar
Bernhard Link committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
-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
117
*=error 13 creating morgue-file ./morgue/bla_1.7.dsc: Permission denied
Bernhard Link's avatar
Bernhard Link committed
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
-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
-v1*=deleting and forgetting 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
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' removed from checksums.db(pool).
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
stderr
=Data seems not to be signed trying to use directly...
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' added to checksums.db(pool).
-d1*=db: 'bla' added to packages.db(test|main|source).
EOF

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

testrun - remove test bla 3<<EOF
stderr
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v1*=removing 'bla' from 'test|main|source'...
-d1*=db: 'bla' removed from packages.db(test|main|source).
-v0*=Deleting files no longer referenced...
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
stderr
*=./pool/main/b/bla/bla_1.7.dsc not found, forgetting anyway
stdout
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' removed from checksums.db(pool).
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
stderr
=Data seems not to be signed trying to use directly...
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' added to checksums.db(pool).
-d1*=db: 'bla' added to packages.db(test|main|source).
EOF

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

testrun - remove test bla 3<<EOF
stderr
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v1*=removing 'bla' from 'test|main|source'...
-d1*=db: 'bla' removed from packages.db(test|main|source).
-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
-v1*=deleting and forgetting 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
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' removed from checksums.db(pool).
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
stderr
=Data seems not to be signed trying to use directly...
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v2*=Created directory "./pool"
-v2*=Created directory "./pool/main"
-v2*=Created directory "./pool/main/b"
-v2*=Created directory "./pool/main/b/bla"
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' added to checksums.db(pool).
-d1*=db: 'bla' added to packages.db(test|main|source).
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
stderr
*=Warning: database 'test|main|source' was modified but no index file was exported.
*=Changes will only be visible after the next 'export'!
stdout
-v1*=removing 'bla' from 'test|main|source'...
-d1*=db: 'bla' removed from packages.db(test|main|source).
-v0*=Deleting files no longer referenced...
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' removed from checksums.db(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
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
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' added to checksums.db(pool).
-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
-v1*=deleting and forgetting pool/main/b/bla/bla_1.7.dsc
-d1*=db: 'pool/main/b/bla/bla_1.7.dsc' removed from checksums.db(pool).
-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