From 533e6fc89eb233f5dbaa15384cfa744e267289b1 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 17 Nov 2015 09:25:20 -0800 Subject: [PATCH] Returns a zero index for a lookup error case. --- consul/state/prepared_query.go | 2 +- consul/state/prepared_query_test.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/consul/state/prepared_query.go b/consul/state/prepared_query.go index 68a94524ca..ce39dea54d 100644 --- a/consul/state/prepared_query.go +++ b/consul/state/prepared_query.go @@ -200,7 +200,7 @@ func (s *StateStore) PreparedQueryLookup(queryIDOrName string) (uint64, *structs // but we check it here to be explicit about it (we'd never want to // return the results from the first query w/o a name). if queryIDOrName == "" { - return idx, nil, ErrMissingQueryID + return 0, nil, ErrMissingQueryID } // Try first by ID if it looks like they gave us an ID. We check the diff --git a/consul/state/prepared_query_test.go b/consul/state/prepared_query_test.go index 49817882ff..e4da659945 100644 --- a/consul/state/prepared_query_test.go +++ b/consul/state/prepared_query_test.go @@ -376,8 +376,15 @@ func TestStateStore_PreparedQueryLookup(t *testing.T) { // Make sure an empty lookup is well-behaved if there are actual queries // in the state store. - if _, _, err = s.PreparedQueryLookup(""); err != ErrMissingQueryID { - t.Fatalf("bad: %v", err) + idx, actual, err = s.PreparedQueryLookup("") + if err != ErrMissingQueryID { + t.Fatalf("bad: %v ", err) + } + if idx != 0 { + t.Fatalf("bad index: %d", idx) + } + if actual != nil { + t.Fatalf("bad: %v", actual) } }