tdb: test for readonly locks mode on tdbbackup command
[vlendec/samba-autobuild/.git] / lib / tdb / test / test_tdbbackup.sh
1 #!/bin/sh
2 # Blackbox test for tdbbackup of given ldb or tdb database
3 # Copyright (C) 2018 Andrew Bartlett <abartlet@samba.org>
4
5 if [ $# -lt 1 ]; then
6         echo "Usage: $0 LDBFILE"
7         exit 1;
8 fi
9
10 LDBFILE=$1
11
12 timestamp() {
13   date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/'
14 }
15
16 subunit_fail_test () {
17   timestamp
18   printf 'failure: %s [\n' "$1"
19   cat -
20   echo "]"
21 }
22
23 testit () {
24         name="$1"
25         shift
26         cmdline="$@"
27         timestamp
28         printf 'test: %s\n' "$1"
29         output=`$cmdline 2>&1`
30         status=$?
31         if [ x$status = x0 ]; then
32                 timestamp
33                 printf 'success: %s\n' "$name"
34         else
35                 echo "$output" | subunit_fail_test "$name"
36         fi
37         return $status
38 }
39
40 $BINDIR/tdbdump $LDBFILE | sort > orig_dump
41
42 testit "normal tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak
43 $BINDIR/tdbdump $LDBFILE.bak | sort > bak_dump
44 testit "cmp between tdbdumps of original and backup" cmp orig_dump bak_dump
45 rm $LDBFILE.bak
46 rm bak_dump
47
48 testit "readonly tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak -r
49 $BINDIR/tdbdump $LDBFILE.bak | sort > bak_dump
50 testit "cmp between tdbdumps of original and back dbs" cmp orig_dump bak_dump
51 rm $LDBFILE.bak
52 rm bak_dump
53
54 rm orig_dump