stream/mts/meta: meta.Get now returns ok bool rather than error - updated usage accordingly

This commit is contained in:
saxon 2019-02-08 10:25:57 +10:30
parent 8bdfed9960
commit a94bdbfe47
2 changed files with 13 additions and 16 deletions

View File

@ -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 doesnt exist.

View File

@ -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")
}
}