stream/mts/meta: meta.Delete no longer returns error - updated code accordingly

This commit is contained in:
saxon 2019-02-08 10:56:19 +10:30
parent a94bdbfe47
commit db3b34c10f
2 changed files with 4 additions and 15 deletions

View File

@ -124,7 +124,7 @@ func (m *Data) Get(key string) (val string, ok bool) {
}
// Delete deletes a meta entry in the map and returns error if it doesnt exist.
func (m *Data) Delete(key string) error {
func (m *Data) Delete(key string) {
m.mu.Lock()
defer m.mu.Unlock()
if _, ok := m.data[key]; ok {
@ -136,9 +136,9 @@ func (m *Data) Delete(key string) error {
break
}
}
return nil
return
}
return errKeyAbsent
return
}
// Encode takes the meta data map and encodes into a byte slice with header

View File

@ -108,23 +108,12 @@ func TestGetAbsentKey(t *testing.T) {
func TestDelete(t *testing.T) {
meta := New()
meta.Add(tstKey1, tstData1)
if err := meta.Delete(tstKey1); err != nil {
t.Errorf("Unexpected err: %v\n", err)
}
meta.Delete(tstKey1)
if _, ok := meta.Get(tstKey1); ok {
t.Error("Get incorrectly returned okay for absent key")
}
}
// TestDeleteAbsentKey checks that we get an expected error when we try to delete
// an entry in the Meta map that doesn't exist.
func TestDeleteAbsentKey(t *testing.T) {
meta := New()
if err := meta.Delete(tstKey1); err != errKeyAbsent {
t.Errorf("Not expected err: %v\n", errKeyAbsent)
}
}
// TestEncode checks that we're getting the correct byte slice from Meta.Encode().
func TestEncode(t *testing.T) {
meta := New()