stream/mts/meta_test.go: added TestGetAbsent key to check that we get an error when we try and get data with key that doesn't exist in metadata map

This commit is contained in:
saxon 2019-01-27 18:15:22 +10:30
parent 17d06f49f4
commit bd54dd128b
2 changed files with 14 additions and 4 deletions

View File

@ -32,6 +32,10 @@ import (
"sync"
)
var (
errKeyAbsent = errors.New("Key does not exist in map")
)
type Meta struct {
mu sync.RWMutex
data map[string]string
@ -51,7 +55,7 @@ func (m *Meta) Add(key, val string) {
// All returns the a copy of the map containing the meta data
func (m *Meta) All() map[string]string {
m.mu.Lock()
var cpy map[string]string
cpy := make(map[string]string)
for k, v := range m.data {
cpy[k] = v
}
@ -65,7 +69,7 @@ func (m *Meta) Get(key string) (string, error) {
val, ok := m.data[key]
m.mu.Unlock()
if !ok {
return "", errors.New("Key does not exist in metadata map")
return "", errKeyAbsent
}
return val, nil

View File

@ -83,8 +83,14 @@ func TestAll(t *testing.T) {
}
}
// TODO: test all
// TODO: test get when key exists
// TODO: test get when key doesn't exist
func TestGetAbsentKey(t *testing.T) {
meta := NewMeta()
if _, err := meta.Get("loc"); err != errKeyAbsent {
t.Errorf("Expected error: %v", errKeyAbsent.Error())
}
}
// TODO: test delete when key exists
// TODO: test delete when key doesn't exist