/tests/t5000-dshbak.sh
Shell | 207 lines | 191 code | 15 blank | 1 comment | 7 complexity | f7a27533dc295143672aba4b7d27d026 MD5 | raw file
1#!/bin/sh 2 3test_description='dshbak functionality' 4 5. ${srcdir:-.}/test-lib.sh 6 7dshbak_test() { 8 printf "$1\n" | dshbak -c > output 9 cat output \ 10 | while read line ; do 11 test "$line" = "$2" && echo ok 12 done | grep -q ok || (cat output >&2 && /bin/false) 13} 14 15dshbak_test_notok() 16{ 17 touch ok 18 printf "$1\n" \ 19 | dshbak -c \ 20 | while read line ; do 21 test "$line" = "$2" && rm ok 22 done 23 rm ok && : 24} 25 26test_expect_success 'dshbak functionality' ' 27 cat >input <<EOF 28foo0: bar 29foo1: bar 30EOF 31 cat >output <<EOF 32---------------- 33foo0 34---------------- 35bar 36---------------- 37foo1 38---------------- 39bar 40EOF 41 dshbak <input >output2 && 42 diff output output2 && 43 rm input output* 44' 45 46 47test_expect_success 'dshbak -c does not coalesce different length output' ' 48 dshbak_test_notok " 49foo1: bar 50foo2: bar 51foo1: baz" "foo[1-2]" 52' 53test_expect_success 'dshbak -c properly compresses multi-digit suffixes' ' 54 dshbak_test " 55foo8: bar 56foo9: bar 57foo10: bar 58foo11: bar" "foo[8-11]" 59' 60 61test_expect_success 'dshbak -c properly compresses prefix with embedded numerals' ' 62 dshbak_test " 63foo1x8: bar 64foo1x9: bar 65foo1x10: bar 66foo1x11: bar" "foo1x[8-11]" 67' 68test_expect_success 'dshbak -c does not strip leading zeros' ' 69 dshbak_test " 70foo01: bar 71foo03: bar 72foo02: bar 73foo00: bar" "foo[00-03]" 74' 75test_expect_success 'dshbak -c does not coalesce different zero padding' ' 76 dshbak_test " 77foo0: bar 78foo03: bar 79foo01: bar 80foo2: bar" "foo[0,01,2,03]" 81' 82test_expect_success 'dshbak -c properly coalesces zero padding of "00"' ' 83 dshbak_test " 84foo1: bar 85foo01: bar 86foo02: bar 87foo3: bar 88foo5: bar 89foo00: bar" "foo[00-02,1,3,5]" 90' 91test_expect_success 'dshbak -c can detect suffixes' ' 92 dshbak_test " 93foo1s: bar 94foo01s: bar 95foo02s: bar 96foo3s: bar 97foo5s: bar 98foo00s: bar" "foo[00-02,1,3,5]s" 99' 100test_expect_failure 'dshbak -c can detect suffix with numeral' ' 101 dshbak_test " 102foo1s0: bar 103foo01s0: bar 104foo02s0: bar 105foo3s0: bar 106foo5s0: bar 107foo00s0: bar" "foo[00-02,1,3,5]s0" 108' 109test_expect_success 'issue 19: missing commas in dshbak header output' ' 110 dshbak_test " 111foo1: bar 112foo2: bar 113foo5: bar 114bar0: bar 115bar1: bar" "bar[0-1],foo[1-2,5]" 116' 117 118test_expect_success 'dshbak properly joins 9,10' ' 119 dshbak_test " 120foo1: bar 121foo2: bar 122foo3: bar 123foo4: bar 124foo5: bar 125foo6: bar 126foo7: bar 127foo8: bar 128foo9: bar 129foo10: bar 130foo11: bar" "foo[1-11]" 131' 132 133test_expect_success 'issue 33: dshbak does not coalesce 09,10' ' 134 dshbak_test " 135foo01: bar 136foo02: bar 137foo03: bar 138foo04: bar 139foo05: bar 140foo06: bar 141foo07: bar 142foo08: bar 143foo09: bar 144foo10: bar 145foo11: bar" "foo[01-11]" 146' 147 148test_expect_success 'issue 33: dshbak does not coalesce 099,100' ' 149 dshbak_test " 150foo090: bar 151foo091: bar 152foo092: bar 153foo093: bar 154foo094: bar 155foo095: bar 156foo096: bar 157foo097: bar 158foo098: bar 159foo099: bar 160foo100: bar 161foo101: bar" "foo[090-101]" 162' 163 164cat >test_input <<EOF 165test 166input 167file 168 foo 169bar 170 171EOF 172 173test_expect_success 'dshbak -d functionality' ' 174 success=t 175 mkdir test_output && 176 pdsh -w foo[0-10] -Rexec cat test_input | dshbak -d test_output && 177 for i in `seq 0 10`; do 178 diff -q test_input test_output/foo$i || success=f, break 179 done && 180 test "$success" = "t" && 181 rm -rf test_output 182' 183test_expect_success 'dshbak -f functionality' ' 184 success=t 185 pdsh -w foo[0-10] -Rexec cat test_input | dshbak -f -d test_output && 186 for i in `seq 0 10`; do 187 diff -q test_input test_output/foo$i || success=f, break 188 done && 189 test "$success" = "t" && 190 rm -rf test_output 191' 192test_expect_success 'dshbak -f without -d fails' ' 193 dshbak -f </dev/null 2>&1 | grep "Option -f may only be used with -d" 194' 195test_expect_success 'dshbak -d fails when output dir does not exist' ' 196 dshbak -d does_not_exist </dev/null 2>&1 | \ 197 grep "Output directory does_not_exist does not exist" 198' 199test_expect_success SANITY 'dshbak -d fails gracefully for non-writable dir' ' 200 mkdir test_output && 201 chmod 500 test_output && 202 printf "foo0: bar\n" | dshbak -d test_output 2>&1 | tee logfile | \ 203 grep "Failed to open output file" && 204 rm -rf test_output logfile || : 205' 206 207test_done