Provide a consistent user experience with prefix based lookups.

* Require at least two characters for identifier
* Automatically strip off the last character in case of uneven length
This commit is contained in:
Ivo Verberk
2016-01-21 22:21:35 +01:00
parent de3bc00a00
commit cc4fea99fc
8 changed files with 83 additions and 26 deletions

View File

@@ -63,11 +63,20 @@ func TestNodeDrainCommand_Fails(t *testing.T) {
}
ui.ErrorWriter.Reset()
// Fail on uneven identifier length
if code := cmd.Run([]string{"-address=" + url, "-enable", "1234567-abcd-efab-cdef-123456789abc"}); code != 1 {
// Fail on identifier with too few characters
if code := cmd.Run([]string{"-address=" + url, "-enable", "1"}); code != 1 {
t.Fatalf("expected exit 1, got: %d", code)
}
if out := ui.ErrorWriter.String(); !strings.Contains(out, "must be of even length.") {
t.Fatalf("expected even length error, got: %s", out)
if out := ui.ErrorWriter.String(); !strings.Contains(out, "must contain at least two characters.") {
t.Fatalf("expected too few characters error, got: %s", out)
}
ui.ErrorWriter.Reset()
// Identifiers with uneven length should produce a query result
if code := cmd.Run([]string{"-address=" + url, "-enable", "123"}); code != 1 {
t.Fatalf("expected exit 1, got: %d", code)
}
if out := ui.ErrorWriter.String(); !strings.Contains(out, "No node(s) with prefix or id") {
t.Fatalf("expected not exist error, got: %s", out)
}
}