From a94bdbfe473e4b41137cfbb90cce0e6b51c1c721 Mon Sep 17 00:00:00 2001 From: saxon Date: Fri, 8 Feb 2019 10:25:57 +1030 Subject: [PATCH] stream/mts/meta: meta.Get now returns ok bool rather than error - updated usage accordingly --- stream/mts/meta/meta.go | 9 +++------ stream/mts/meta/meta_test.go | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/stream/mts/meta/meta.go b/stream/mts/meta/meta.go index bb8b1161..297b2fa2 100644 --- a/stream/mts/meta/meta.go +++ b/stream/mts/meta/meta.go @@ -116,14 +116,11 @@ func (m *Data) All() map[string]string { } // Get returns the meta data for the passed key. -func (m *Data) Get(key string) (string, error) { +func (m *Data) Get(key string) (val string, ok bool) { m.mu.Lock() - val, ok := m.data[key] + val, ok = m.data[key] m.mu.Unlock() - if !ok { - return "", errKeyAbsent - } - return val, nil + return } // Delete deletes a meta entry in the map and returns error if it doesn’t exist. diff --git a/stream/mts/meta/meta_test.go b/stream/mts/meta/meta_test.go index cb770883..a97d925f 100644 --- a/stream/mts/meta/meta_test.go +++ b/stream/mts/meta/meta_test.go @@ -47,15 +47,15 @@ func TestAddAndGet(t *testing.T) { meta := New() meta.Add(tstKey1, tstData1) meta.Add(tstKey2, tstData2) - if data, err := meta.Get(tstKey1); err != nil { - t.Errorf("Could not get data for key: loc: %v", err) + if data, ok := meta.Get(tstKey1); !ok { + t.Errorf("Could not get data for key: %v\n", tstKey1) if data != tstData1 { t.Error("Did not get expected data") } } - if data, err := meta.Get(tstKey2); err != nil { - t.Errorf("Could not get data for key: ts: %v", err) + if data, ok := meta.Get(tstKey2); !ok { + t.Errorf("Could not get data for key: %v", tstKey2) if data != tstData2 { t.Error("Did not get expected data") } @@ -69,8 +69,8 @@ func TestUpdate(t *testing.T) { meta.Add(tstKey1, tstData1) meta.Add(tstKey1, tstData3) - if data, err := meta.Get(tstKey1); err != nil { - t.Errorf("Unexpected err: %v\n", err) + if data, ok := meta.Get(tstKey1); !ok { + t.Errorf("Could not get data for key: %v\n", tstKey1) if data != tstData2 { t.Error(`Data did not correctly update for key "loc"`) } @@ -99,8 +99,8 @@ func TestAll(t *testing.T) { func TestGetAbsentKey(t *testing.T) { meta := New() - if _, err := meta.Get(tstKey1); err != errKeyAbsent { - t.Errorf("Not expected err: %v\n", errKeyAbsent) + if _, ok := meta.Get(tstKey1); ok { + t.Error("Get for absent key incorrectly returned'ok'") } } @@ -111,8 +111,8 @@ func TestDelete(t *testing.T) { if err := meta.Delete(tstKey1); err != nil { t.Errorf("Unexpected err: %v\n", err) } - if _, err := meta.Get(tstKey1); err != errKeyAbsent { - t.Errorf("Not expected err. got: %v\n, want: $%v\n", err, errKeyAbsent) + if _, ok := meta.Get(tstKey1); ok { + t.Error("Get incorrectly returned okay for absent key") } }