display and/or create md5sum in user.md5 xattr
[cloudstore.git] / test.sh
1 #!/bin/sh -xe
2
3 RSYNC_LOGIN=fake
4
5 push() {
6         file=`shift`
7         RSYNC_PASSWORD=secret rsync $* $file rsync://$RSYNC_LOGIN@127.0.0.1:6501/$RSYNC_LOGIN/localhost/$file
8 }
9 pull() {
10         from=$1
11         to=$2
12         test -z "$to" && to=$1
13         RSYNC_PASSWORD=secret rsync rsync://$RSYNC_LOGIN@127.0.0.1:6501/$RSYNC_LOGIN/localhost/$from $to
14 }
15
16
17 #sudo ./remove-user.sh test@example.com
18 #sudo ./remove-user.sh test2@example.com
19 base_dir=`pwd`
20
21 RSYNC_LOGIN=`sudo ./create-user.sh test@example.com secret 500000`
22 RSYNC_LOGIN2=`sudo ./create-user.sh test2@example.com secret 100000`
23
24 . ./env.sh
25
26 dir=/tmp/test
27 rm -Rf "$dir"
28 mkdir /tmp/test
29 cd $dir
30
31 push . --recursive --delete -v
32
33 if [ ! -z "$ALL" ] ; then # skip tests if false
34
35 ps ax > foo
36 push foo -v
37 push foo -v
38 ps ax > bar
39 push bar -v
40 touch --date='2000-01-01' bar
41 push bar -v
42 pull bar baz
43 push baz -v
44 ps ax >> baz
45 push baz -v
46 cp baz baz2
47 push baz baz2 -v
48
49 mkdir dir-test
50 # deduplicate?
51 cp foo bar dir-test/
52 uptime > "dir-test/file with spaces"
53 push dir-test --recursive -v
54
55 find . type -f | xargs -i md5sum {} > /tmp/md5sum
56
57 rm foo bar
58 push dir-test --recursive --delete -v
59 rm -Rf dir-test
60
61 pull non-existing || true
62
63 cp /tmp/md5sum md5sum
64 mkdir clone
65 # test md5 import from directory
66 mv md5sum clone/
67 push clone -r -v
68 # client should hardlink or copy files locally to avoid wastefull pull
69 # but we test server-side hardlink here
70 pull clone -r -v
71
72 md5sum clone/* | sed -e 's!  !  _import/foo/bar/baz!' > md5sum
73 cat md5sum
74 push md5sum -v
75
76 # test unused md5 pool quota
77
78 ps ax > tmp
79 push tmp -v
80 rm tmp
81 push . -r --delete -v
82
83 # test send
84
85 ps ax >> send
86 mkdir dir1
87 ps ax >> dir1/send
88 mkdir dir2
89 ps ax >> dir2/send
90
91 mkdir -p .sync/send
92 cat << __SEND__ > .sync/send/timestamp
93 $RSYNC_LOGIN2 send
94 $RSYNC_LOGIN2 dir1/send
95 $RSYNC_LOGIN2 dir2/send
96 __SEND__
97
98 # order is important! .sync must be last!
99 push send dir1 dir2 .sync -rv
100
101 # test receiving of sent files
102 mkdir /tmp/test/$RSYNC_LOGIN2
103 RSYNC_PASSWORD=secret rsync -rv rsync://$RSYNC_LOGIN2@127.0.0.1:6501/$RSYNC_LOGIN2/received/ /tmp/test/$RSYNC_LOGIN2
104
105 fi # skip tests
106
107 # test file move
108
109 ps ax > Jellyfish.jpg
110 push Jellyfish.jpg
111
112 mkdir -p .sync/pending
113 cat << __pending__ > .sync/pending/test
114 MOVED#Jellyfish.jpg#Photos with space/Jellyfish cool.jpg
115 DELETED#Photos with space/Jellyfish cool.jpg
116 DELETED#Photos with space
117 __pending__
118
119 push .sync -rv
120
121 exit
122
123 ps ax > perms-test
124 chmod 400 perms-test
125 push -va perms-test
126
127 sudo sh -xc "ls -al ~$RSYNC_LOGIN/localhost/"
128
129
130
131
132 find $SLICE/2001/ -type f | grep -v '/\.' | xargs md5sum | sort > /tmp/test/1
133 FULL=1 $base_dir/user-md5sum.pl u2001 | sort > /tmp/test/2
134
135 diff /tmp/test/1 /tmp/test/2 && echo "OK - md5 database consistant with filesystem"
136