mirror of https://bitbucket.org/ausocean/av.git
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:
parent
17d06f49f4
commit
bd54dd128b
|
@ -32,6 +32,10 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errKeyAbsent = errors.New("Key does not exist in map")
|
||||||
|
)
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
data map[string]string
|
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
|
// All returns the a copy of the map containing the meta data
|
||||||
func (m *Meta) All() map[string]string {
|
func (m *Meta) All() map[string]string {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
var cpy map[string]string
|
cpy := make(map[string]string)
|
||||||
for k, v := range m.data {
|
for k, v := range m.data {
|
||||||
cpy[k] = v
|
cpy[k] = v
|
||||||
}
|
}
|
||||||
|
@ -65,7 +69,7 @@ func (m *Meta) Get(key string) (string, error) {
|
||||||
val, ok := m.data[key]
|
val, ok := m.data[key]
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", errors.New("Key does not exist in metadata map")
|
return "", errKeyAbsent
|
||||||
}
|
}
|
||||||
|
|
||||||
return val, nil
|
return val, nil
|
||||||
|
|
|
@ -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
|
// 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 exists
|
||||||
// TODO: test delete when key doesn't exist
|
// TODO: test delete when key doesn't exist
|
||||||
|
|
Loading…
Reference in New Issue