From e3710a991e8a190b80a800c8bc91a1f36811e091 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 29 Aug 2017 10:09:30 -0700 Subject: [PATCH] add prefix tests --- command/alloc_status_test.go | 19 +++++++++++++++++++ command/monitor_test.go | 2 +- command/node_status_test.go | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/command/alloc_status_test.go b/command/alloc_status_test.go index b17cfc9d7..f858eaf6b 100644 --- a/command/alloc_status_test.go +++ b/command/alloc_status_test.go @@ -144,6 +144,25 @@ func TestAllocStatusCommand_Run(t *testing.T) { t.Fatalf("expected to have 'Created At' but saw: %s", out) } ui.OutputWriter.Reset() + + // Try the query with an even prefix that includes the hyphen + if code := cmd.Run([]string{"-address=" + url, allocId1[:13]}); code != 0 { + t.Fatalf("expected exit 0, got: %d", code) + } + out = ui.OutputWriter.String() + if !strings.Contains(out, "Created At") { + t.Fatalf("expected to have 'Created At' but saw: %s", out) + } + ui.OutputWriter.Reset() + + if code := cmd.Run([]string{"-address=" + url, "-verbose", allocId1}); code != 0 { + t.Fatalf("expected exit 0, got: %d", code) + } + out = ui.OutputWriter.String() + if !strings.Contains(out, allocId1) { + t.Fatal("expected to find alloc id in output") + } + ui.OutputWriter.Reset() } func TestAllocStatusCommand_AutocompleteArgs(t *testing.T) { diff --git a/command/monitor_test.go b/command/monitor_test.go index a6dbf2253..53e7c5e58 100644 --- a/command/monitor_test.go +++ b/command/monitor_test.go @@ -239,7 +239,7 @@ func TestMonitor_MonitorWithPrefix(t *testing.T) { doneCh := make(chan struct{}) go func() { defer close(doneCh) - code = mon.monitor(resp.EvalID[:8], true) + code = mon.monitor(resp.EvalID[:13], true) }() // Wait for completion diff --git a/command/node_status_test.go b/command/node_status_test.go index bb1e5ac9c..a3ec59f53 100644 --- a/command/node_status_test.go +++ b/command/node_status_test.go @@ -127,8 +127,8 @@ func TestNodeStatusCommand_Run(t *testing.T) { t.Fatalf("should not dump allocations") } - // Query a single node based on prefix - if code := cmd.Run([]string{"-address=" + url, nodeID[:4]}); code != 0 { + // Query a single node based on a prefix that is even without the hyphen + if code := cmd.Run([]string{"-address=" + url, nodeID[:13]}); code != 0 { t.Fatalf("expected exit 0, got: %d", code) } out = ui.OutputWriter.String()