]> pd.if.org Git - zpackage/blob - t/extract.t
add extract test file
[zpackage] / t / extract.t
1 #!/bin/sh
2
3 # test addfile
4
5 tn=0
6 planned=0
7
8 shownote() {
9         if [ "$note" != "" ]; then
10                 printf '# %s\n' "$note"
11         fi
12 }
13
14 okexit() {
15         exitwith 0 "$*"
16 }
17
18 failsok() {
19         note=
20         if [ $? -eq 0 ]; then
21                 printf 'not ';
22                 note=$(printf '# got "%d" expected "%d"' "$1" "0")
23         fi
24         tn=$((tn + 1))
25         printf 'ok %d - %s\n' $tn "$*"
26         shownote
27 }
28
29 exitwith() {
30         note=
31         if [ $? -ne $1 ]; then
32                 printf 'not ';
33                 note=$(printf '# got "%d" expected "%d"' "$1" "$2")
34         fi
35         shift
36         tn=$((tn + 1))
37         printf 'ok %d - %s\n' $tn "$*"
38         shownote
39 }
40
41 okstreq() {
42         note=
43         if [ "$1" != "$2" ]; then
44                 printf 'not ';
45                 note=$(printf 'got "%s" expected "%s"' "$1" "$2")
46         fi
47
48         shift;shift;
49         tn=$((tn + 1))
50         printf 'ok %d - %s\n' $tn "$*"
51         shownote
52 }
53
54 plan() {
55         planned=$1
56         printf '1..%d\n' $planned
57 }
58
59 finish() {
60         if [ $planned -eq 0 ]; then
61                 printf '1..%d\n' $tn
62         fi
63 }
64
65 plan 4
66
67 PF=test.db
68
69 rm -f $PF test.foo
70 echo foo > test.foo
71
72 hash=$(./zpm-addfile $PF test.foo 2>> test.out)
73 save=$?
74
75 okexit add foo file content
76 okstreq $hash b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c foo hash contents
77
78 rm -f foo
79
80 ./zpm-extract $PF $hash foo
81 okexit  extract foo file content
82
83 sha=$(sha256sum foo)
84 okstreq $hash $sha extracted hash matches
85
86 finish
87
88 #rm -f $PF test.empty