From 46d5afa57461b712ee7edde28c061007aac45443 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Sat, 14 Nov 2015 16:13:40 -0800 Subject: [PATCH] Adds a test to ensure we don't return a nil slice. --- consul/state/prepared_query_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/consul/state/prepared_query_test.go b/consul/state/prepared_query_test.go index d47fab840c..bb057ec972 100644 --- a/consul/state/prepared_query_test.go +++ b/consul/state/prepared_query_test.go @@ -379,6 +379,18 @@ func TestStateStore_PreparedQueryLookup(t *testing.T) { func TestStateStore_PreparedQueryList(t *testing.T) { s := testStateStore(t) + // Make sure an empty (non-nil) slice is returned if there are no queries. + idx, actual, err := s.PreparedQueryList() + if err != nil { + t.Fatalf("err: %s", err) + } + if idx != 0 { + t.Fatalf("bad index: %d", idx) + } + if actual == nil || len(actual) != 0 { + t.Fatalf("bad: %v", actual) + } + // Set up our test environment. testRegisterNode(t, s, 1, "foo") testRegisterService(t, s, 2, "foo", "redis") @@ -439,7 +451,7 @@ func TestStateStore_PreparedQueryList(t *testing.T) { }, }, } - idx, actual, err := s.PreparedQueryList() + idx, actual, err = s.PreparedQueryList() if err != nil { t.Fatalf("err: %s", err) }