/tests/t0003-wcoll.sh

https://code.google.com/ · Shell · 173 lines · 148 code · 13 blank · 12 comment · 0 complexity · ece0d3c972baedf7d0242c0ce2c5e776 MD5 · raw file

  1. #!/bin/sh
  2. test_description='pdsh wcoll (working collective) argument processing'
  3. . ${srcdir:-.}/test-lib.sh
  4. #
  5. # Wrapper to check last line of output from pdsh -Qw
  6. # test_pdsh_wcoll <hostlist> <expected output> [<extra args>]
  7. #
  8. test_pdsh_wcoll() {
  9. OUTPUT=$(pdsh -Qw $1 $3 | tail -1)
  10. test_output_is_expected "$OUTPUT" "$2"
  11. }
  12. test_expect_success 'hostname range expansion works' '
  13. test_pdsh_wcoll "foo[0-3]" "foo0,foo1,foo2,foo3"
  14. '
  15. test_expect_success 'host range expansion does not strip leading zeros' '
  16. test_pdsh_wcoll "foo[00-02]" "foo00,foo01,foo02"
  17. '
  18. test_expect_success 'host range expansion handles mixed size suffixes' '
  19. test_pdsh_wcoll "foo[9-11]" "foo9,foo10,foo11"
  20. '
  21. test_expect_success 'host range expansion works with "," embedded in range' '
  22. test_pdsh_wcoll "foo[0-2,4]" "foo0,foo1,foo2,foo4"
  23. '
  24. test_expect_success 'host range expansion works with 2 sets of brackets' '
  25. test_pdsh_wcoll "foo[1-2]-[0-3]" \
  26. "foo1-0,foo1-1,foo1-2,foo1-3,foo2-0,foo2-1,foo2-2,foo2-3"
  27. '
  28. test_expect_success 'pdsh -x option works' '
  29. test_pdsh_wcoll "foo[9-11]" "foo9,foo11" "-x foo10"
  30. '
  31. test_expect_success 'pdsh -x option works with ranges' '
  32. test_pdsh_wcoll "foo[0-5]" "foo0,foo4,foo5" "-x foo[1-3]"
  33. '
  34. test_expect_success 'pdsh -x option works with ranges (gnats:118)' '
  35. test_pdsh_wcoll "foo[0-5]" "foo0,foo4,foo5" "-x foo[1-3]"
  36. '
  37. test_expect_success 'pdsh -x option works with non-numeric suffix (gnats:120)' '
  38. test_pdsh_wcoll "fooi,fooj,foo[0-5]" \
  39. "foo0,foo1,foo3,foo4,foo5" \
  40. "-x fooj,fooi,foo2"
  41. '
  42. test_expect_success 'pdsh -w- reads from stdin' '
  43. echo "foo1,foo2,foo3" | test_pdsh_wcoll "-" "foo1,foo2,foo3"
  44. '
  45. test_expect_success 'pdsh -w- can be used with other -w args' '
  46. echo "foo1,foo2,foo3" | test_pdsh_wcoll "-" "foo1,foo2,foo3,foo4" "-wfoo4"
  47. '
  48. cat >wcoll <<EOF
  49. foo1
  50. foo2
  51. foo3
  52. EOF
  53. test_expect_success 'WCOLL environment variable works' '
  54. test_output_is_expected "$(WCOLL=wcoll pdsh -q | tail -1)" "foo[1-3]"
  55. '
  56. cat >wcoll <<EOF
  57. foo[9-11]
  58. foo12
  59. EOF
  60. test_expect_success 'ranges can be embedded in wcoll files' '
  61. test_output_is_expected "$(WCOLL=wcoll pdsh -Q | tail -1)" \
  62. "foo9,foo10,foo11,foo12"
  63. '
  64. test_expect_success '^file works' '
  65. test_pdsh_wcoll "^./wcoll" "foo9,foo10,foo11,foo12"
  66. '
  67. test_expect_success '-x ^file works' '
  68. test_pdsh_wcoll "foo[8-13]" "foo8,foo13" "-x^wcoll"
  69. '
  70. test_expect_success '^file works with other args' '
  71. test_pdsh_wcoll "foo[1-2],^./wcoll" "foo1,foo2,foo9,foo10,foo11,foo12"
  72. '
  73. cat >A <<EOF
  74. foo1
  75. foo2
  76. EOF
  77. cat >B <<EOF
  78. foo7
  79. foo8
  80. EOF
  81. test_expect_success 'Multiple ^file args' '
  82. test_pdsh_wcoll "^A,^B" "foo1,foo2,foo7,foo8"
  83. '
  84. test_expect_success 'Multiple -w^file' '
  85. test_pdsh_wcoll "^A" "foo1,foo2,foo7,foo8" "-w^B"
  86. '
  87. test_expect_success '-^file excludes hosts in file' '
  88. test_pdsh_wcoll "foo[8-12],-^./wcoll" "foo8"
  89. '
  90. test_expect_success '^file errors out if file doesnt exist' '
  91. ! pdsh -w "^nosuchfile" -q 2>/dev/null &&
  92. pdsh -w "^nosuchfile" -q 2>&1 | grep -q "nosuchfile: No such file"
  93. '
  94. test_expect_success 'host exclusion with "-" works' '
  95. test_pdsh_wcoll "foo[9-11],-foo10" "foo9,foo11"
  96. '
  97. test_expect_success 'regex filtering works' '
  98. test_pdsh_wcoll "foo[0-20],/0$/" "foo0,foo10,foo20"
  99. '
  100. test_expect_success 'regex exclusion works' '
  101. test_pdsh_wcoll "foo[0-20],-/[1-9]$/" "foo0,foo10,foo20"
  102. '
  103. test_expect_success 'regex exclusion works from -x' '
  104. test_pdsh_wcoll "foo[0-20]" "foo0,foo10,foo20" "-x/[1-9]$/"
  105. '
  106. test_expect_success 'multiple -w options' '
  107. test_pdsh_wcoll "foo[0-20]" "foo0,foo10,foo20" "-w-/[1-9]$/" &&
  108. test_pdsh_wcoll "foo8" "foo8,foo9,foo10,foo11,foo12" "-w^wcoll" &&
  109. test_pdsh_wcoll "foo1,bar1" "foo1" "-w/^foo/"
  110. '
  111. cat >A <<EOF
  112. foo1
  113. #include B
  114. EOF
  115. cat >B <<EOF
  116. foo2
  117. EOF
  118. test_expect_success 'wcoll files support #include syntax' '
  119. test_pdsh_wcoll "^A" "foo1,foo2"
  120. '
  121. mkdir testdir
  122. cat >testdir/A <<EOF
  123. foo1
  124. foo2
  125. #include B
  126. EOF
  127. cat >testdir/B <<EOF
  128. foo10
  129. EOF
  130. test_expect_success 'wcoll #include syntax searches dirname of orignal file' '
  131. test_pdsh_wcoll "^testdir/A" "foo1,foo2,foo10"
  132. '
  133. cat >testdir/A <<EOF
  134. foo1
  135. foo2
  136. #include B garbage
  137. EOF
  138. cat >testdir/B <<EOF
  139. #
  140. #included A
  141. foo10
  142. EOF
  143. cat >testdir/C <<EOF
  144. #
  145. #include
  146. foo11
  147. EOF
  148. test_expect_success 'wcoll #include syntax ignores malformed lines' '
  149. test_pdsh_wcoll "^testdir/A" "foo1,foo2" &&
  150. pdsh -w^testdir/A -q 2>&1 | grep -q warning
  151. '
  152. test_expect_success 'wcoll match #include exactly' '
  153. test_pdsh_wcoll "^testdir/B" "foo10" &&
  154. pdsh -w^testdir/B -q 2>&1 | grep -q warning
  155. '
  156. test_expect_success 'wcoll: #include alone fails' '
  157. test_pdsh_wcoll "^testdir/C" "foo11" &&
  158. pdsh -w^testdir/C -q 2>&1 | grep -q warning
  159. '
  160. test_done