Test suite: Fix bug in node_has_status().
authorMartin Schwenke <martin@meltin.net>
Tue, 20 Oct 2009 05:45:29 +0000 (16:45 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 20 Oct 2009 05:45:29 +0000 (16:45 +1100)
This function has been broken since it was updated to work with the
"stopped" state (probably commit
67c5bfb5f02c9d45a32d976021ede4fb2174dfe9).  Although ${var#:*:0}
removes the shortest matching prefix of $var, '*' can match substrings
that include ':' if '0' isn't where you expect.  So we were making
unexpected matches and incorrectly returning true for some cases.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/scripts/ctdb_test_functions.bash

index 40d8453e5671169092a651220bfcd1cdd8819910..8de0d4b2b7cfd65d34ad72a12de817c251874aca 100644 (file)
@@ -396,7 +396,10 @@ node_has_status ()
        {
             read x
             while read line ; do
-               [ "${line#:${pnn}:*:${bits}}" != "$line" ] && return 0
+               # This needs to be done in 2 steps to avoid false matches.
+               local line_bits="${line#:${pnn}:*:}"
+               [ "$line_bits" = "$line" ] && continue
+               [ "${line_bits#${bits}}" != "$line_bits" ] && return 0
             done
            return 1
        } <<<"$out" # Yay bash!