|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='test framework and pdsh basics' |
| 4 | + |
| 5 | +if ! test -x ../src/pdsh/pdsh; then |
| 6 | + echo >&2 'Failed to find pdsh binary. Please run make.' |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | + |
| 10 | +. ${srcdir:-.}/test-lib.sh |
| 11 | + |
| 12 | +########################################################################### |
| 13 | +# |
| 14 | +# Tests of the framework. From git teststuite: |
| 15 | +# |
| 16 | +test_expect_success 'working success' '/bin/true' |
| 17 | + |
| 18 | +test_set_prereq HAVEIT |
| 19 | +haveit=no |
| 20 | +test_expect_success HAVEIT 'test runs if prerequisite is satisfied' ' |
| 21 | + test_have_prereq HAVEIT && |
| 22 | + haveit=yes |
| 23 | +' |
| 24 | + |
| 25 | +clean=no |
| 26 | +test_expect_success 'tests clean up after themselves' ' |
| 27 | + test_when_finished clean=yes |
| 28 | +' |
| 29 | + |
| 30 | +cleaner=no |
| 31 | +test_expect_code 1 'tests clean up even after a failure' ' |
| 32 | + test_when_finished cleaner=yes && |
| 33 | + (exit 1) |
| 34 | +' |
| 35 | + |
| 36 | +if test $clean$cleaner != yesyes |
| 37 | +then |
| 38 | + say "bug in test framework: cleanup commands do not work reliably" |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +test_expect_code 2 'failure to clean up causes the test to fail' ' |
| 43 | + test_when_finished "(exit 2)" |
| 44 | +' |
| 45 | + |
| 46 | +########################################################################### |
| 47 | +# |
| 48 | +# Basic pdsh functionality |
| 49 | +# |
| 50 | +test_expect_success 'pdsh runs' ' |
| 51 | + pdsh -w foo -q | tail -1 | grep foo |
| 52 | +' |
| 53 | +test_expect_success 'pdsh -V works' ' |
| 54 | + pdsh -V 2>&1 | grep -q ^pdsh |
| 55 | +' |
| 56 | +test_expect_success 'pdsh -L works' ' |
| 57 | + pdsh -L 2>&1 | grep -q ^Module: |
| 58 | +' |
| 59 | +test_expect_success 'pdsh -h works' ' |
| 60 | + pdsh -h 2>&1 | grep Usage: |
| 61 | +' |
| 62 | +test_expect_success 'rcmd/exec module is built' ' |
| 63 | + test_have_prereq MOD_RCMD_EXEC && havit=yes |
| 64 | +' |
| 65 | +test_expect_success 'pdsh -N option works' ' |
| 66 | + O1=$(pdsh -Rexec -w foo0 echo foo | sed "s/foo0: //") |
| 67 | + O2=$(pdsh -NRexec -w foo0 echo foo) |
| 68 | + if ! test "$O1" = "$O2"; then |
| 69 | + say_color error "Error: -N output \"$O1\" != \"$O2\"" |
| 70 | + false |
| 71 | + fi |
| 72 | +' |
| 73 | + |
| 74 | +run_timeout() { |
| 75 | + perl -e 'alarm shift @ARGV; exec @ARGV' "$@" |
| 76 | +} |
| 77 | +test_expect_success LONGTESTS '-u option is functional' ' |
| 78 | + run_timeout 5 pdsh -wfoo -Rexec -u 1 sleep 10 2>&1 \ |
| 79 | + | grep -i "command timeout" |
| 80 | +' |
| 81 | + |
| 82 | +check_pdsh_option() { |
| 83 | + flag=$1; name=$2; value=$3; |
| 84 | + flagval=$value |
| 85 | + if test "$value" = "Yes" -o "$value" = "No"; then |
| 86 | + flagval="" |
| 87 | + fi |
| 88 | + echo "flag=$flag name='$name' value=$value flagval=$flagval" |
| 89 | + pdsh -$flag$flagval -w foo -q | grep -q "$name[ ]*$value$" |
| 90 | +} |
| 91 | + |
| 92 | +test_expect_success '-f sets fanout' ' |
| 93 | + check_pdsh_option f Fanout 8 |
| 94 | +' |
| 95 | +test_expect_success '-l sets remote username' ' |
| 96 | + check_pdsh_option l "Remote username" foouser |
| 97 | +' |
| 98 | +test_expect_success '-t sets connect timeout' ' |
| 99 | + check_pdsh_option t "Connect timeout (secs)" 33 |
| 100 | +' |
| 101 | +test_expect_success '-u sets command timeout' ' |
| 102 | + check_pdsh_option u "Command timeout (secs)" 22 |
| 103 | +' |
| 104 | +test_expect_success 'command timeout 0 by default' ' |
| 105 | + pdsh -w foo -q | grep -q "Command timeout (secs)[ ]*0$" |
| 106 | +' |
| 107 | +test_expect_success '-b enables batch mode' ' |
| 108 | + check_pdsh_option b "one \^C will kill pdsh" Yes |
| 109 | +' |
| 110 | +test_expect_success 'pdsh -N option works' ' |
| 111 | + O1=$(pdsh -Rexec -w foo0 echo foo | sed "s/foo0: //") |
| 112 | + O2=$(pdsh -NRexec -w foo0 echo foo) |
| 113 | + if ! test "$O1" = "$O2"; then |
| 114 | + say_color error "Error: -N output \"$O1\" != \"$O2\"" |
| 115 | + false |
| 116 | + fi |
| 117 | +' |
| 118 | +test_done |
0 commit comments