|
| 1 | +#!/bin/sh |
| 2 | +# {Watch ./apply_test.sh} |
| 3 | + |
| 4 | +tests=`sed -n '/^test.*[(][)].*{/ s/[^A-Za-z0-9_]*//gp' $0` |
| 5 | + |
| 6 | +testapplyafresh() { |
| 7 | + r=/tmp/replica.${testname?} o=$r/old n=$r/new |
| 8 | + rm -rf $r |
| 9 | + mkdir $r $o $o/dir1 $n |
| 10 | + echo t > $o/file1 || exit |
| 11 | + rm -f $r/time |
| 12 | + { |
| 13 | + echo '1648215000 0 a dir0 - d755 user staff 1648208130 0' |
| 14 | + echo '1648215000 1 a dir1 - d755 user staff 1648208130 0' |
| 15 | + echo '1648215000 2 a file1 - 644 user staff 1648208130 2' |
| 16 | + echo '1648215000 3 a cp1 file1 644 user staff 1648208130 2' |
| 17 | + } >$r/log |
| 18 | + sh ./apply.sh $o $n $r/time <$r/log >$r/out || exit |
| 19 | + ( |
| 20 | + set -x |
| 21 | + test -e $n/dir0 || exit |
| 22 | + test -d $n/dir1 || exit |
| 23 | + test -f $n/file1 || exit |
| 24 | + test -w $n/file1 || exit |
| 25 | + cmp $n/cp1 $o/file1 || exit |
| 26 | + nr=`wc -l <$r/out` && test "$nr" -eq 4 || exit |
| 27 | + time=`cat $r/time` && test "$time" = '1648215000 3' || exit |
| 28 | + ) 2>$r/err || { cat $r/err; exit 1; } |
| 29 | + rm -r "$r" |
| 30 | +} |
| 31 | + |
| 32 | +testapplyresumed() { |
| 33 | + r=/tmp/replica.${testname?} o=$r/old n=$r/new |
| 34 | + rm -rf $r |
| 35 | + mkdir $r $o $o/dir1 $n |
| 36 | + touch $o/file1 $o/dir1/file2 || exit |
| 37 | + echo 1648215015 0 > $r/time |
| 38 | + { |
| 39 | + echo '1648215015 0 a shadowed - d755 user staff 1648208130 0' |
| 40 | + echo '1648215015 1 a dir1 - d755 user staff 1648208130 0' |
| 41 | + echo '1648215015 2 a file1 - 644 user staff 1648208130 0' |
| 42 | + echo '1648215015 3 a dir1/file2 - 444 user staff 1648208130 0' |
| 43 | + echo '1648215015 4 a dir2 - d755 user staff 1648208130 0' |
| 44 | + } >$r/log |
| 45 | + sh ./apply.sh $o $n $r/time <$r/log >$r/out || exit |
| 46 | + ( |
| 47 | + set -x |
| 48 | + test ! -e $n/shadowed || exit |
| 49 | + test -d $n/dir1 || exit |
| 50 | + test -f $n/file1 || exit |
| 51 | + test -w $n/file1 || exit |
| 52 | + test -f $n/dir1/file2 || exit |
| 53 | + test ! -w $n/dir1/file2 || exit |
| 54 | + test -d $n/dir2 || exit |
| 55 | + time=`cat $r/time` && test "$time" = '1648215015 4' || exit |
| 56 | + ) 2>$r/err || { cat $r/err; exit 1; } |
| 57 | + |
| 58 | + { |
| 59 | + echo '1648216000 0 m dir1/file2 - d644 user staff 1648208130 0' |
| 60 | + echo '1648216000 1 d file1 - 744 user staff 1648208130 0' |
| 61 | + echo '1648216000 2 d dir2 - d744 user staff 1648208130 0' |
| 62 | + } >>$r/log |
| 63 | + sh ./apply.sh $o $n $r/time <$r/log >$r/out || exit |
| 64 | + ( |
| 65 | + set -x |
| 66 | + test -w $n/dir1/file2 || exit |
| 67 | + test '!' -e $n/file1 || exit |
| 68 | + test '!' -e $n/dir2 || exit |
| 69 | + nr=`wc -l < $r/out` && test "$nr" -eq 3 || exit |
| 70 | + time=`cat $r/time` && test "$time" = '1648216000 2' || exit |
| 71 | + ) 2>$r/err || { cat $r/err; exit 1; } |
| 72 | +} |
| 73 | + |
| 74 | +testapplydeleted() { |
| 75 | + r=/tmp/replica.${testname?} o=$r/old n=$r/new |
| 76 | + rm -rf $r |
| 77 | + mkdir $r $o $n |
| 78 | + rm -f $r/time |
| 79 | + { |
| 80 | + echo '1648217000 0 a file1 - 644 user staff 1648208130 2' |
| 81 | + echo '1648217001 0 d file1 - 644 user staff 1648208130 2' |
| 82 | + } >$r/log |
| 83 | + sh ./apply.sh $o $n $r/time <$r/log >$r/out || exit |
| 84 | + ( |
| 85 | + set -x |
| 86 | + test ! -e $n/file1 || exit |
| 87 | + time=`cat $r/time` && test "$time" = '1648217001 0' || exit |
| 88 | + ) 2>$r/err || { cat $r/err; exit 1; } |
| 89 | + rm -r "$r" |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +p='' |
| 94 | +for t in $tests |
| 95 | +do testname=$t $t & |
| 96 | + p=$p' '$! |
| 97 | +done |
| 98 | + |
| 99 | +err='' |
| 100 | +for i in $p |
| 101 | +do wait $i || err=$? |
| 102 | +done |
| 103 | +test -z $err && echo ok |
0 commit comments