mirror of https://bitbucket.org/ausocean/av.git
stream/mts/meta_test.go: using consts for commonly occuring test strings
This commit is contained in:
parent
7fc2b76e6b
commit
e1ac1ac5d4
|
@ -28,40 +28,47 @@ LICENSE
|
|||
package mts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TODO: test add when key doesn't exist
|
||||
const (
|
||||
tstKey1 = "loc"
|
||||
tstData1 = "a,b,c"
|
||||
tstKey2 = "ts"
|
||||
tstData2 = "12345678"
|
||||
tstData3 = "d,e,f"
|
||||
)
|
||||
|
||||
func TestAddAndGet(t *testing.T) {
|
||||
meta := NewMeta()
|
||||
meta.Add("loc", "a,b,c")
|
||||
meta.Add("ts", "12345678")
|
||||
|
||||
if data, err := meta.Get("loc"); err != nil {
|
||||
meta.Add(tstKey1, tstData1)
|
||||
meta.Add(tstKey2, tstData2)
|
||||
errors.New("Trying to delete map entry that doesn't exist")
|
||||
if data, err := meta.Get(tstKey1); err != nil {
|
||||
t.Errorf("Could not get data for key: loc: %v", err.Error())
|
||||
if data != "a,b,c" {
|
||||
if data != tstData1 {
|
||||
t.Errorf("Did not get expected data")
|
||||
}
|
||||
}
|
||||
|
||||
if data, err := meta.Get("ts"); err != nil {
|
||||
if data, err := meta.Get(tstKey2); err != nil {
|
||||
t.Errorf("Could not get data for key: ts: %v", err.Error())
|
||||
if data != "12345678" {
|
||||
if data != tstData2 {
|
||||
t.Errorf("Did not get expected data")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test add when key does exist
|
||||
func TestUpdate(t *testing.T) {
|
||||
meta := NewMeta()
|
||||
meta.Add("loc", "a,b,c")
|
||||
meta.Add("loc", "d,e,f")
|
||||
meta.Add(tstKey1, tstData1)
|
||||
meta.Add(tstKey1, tstData3)
|
||||
|
||||
if data, err := meta.Get("loc"); err != nil {
|
||||
if data, err := meta.Get(tstKey1); err != nil {
|
||||
t.Errorf("Did not expect err: %v", err.Error())
|
||||
if data != "d,e,f" {
|
||||
if data != tstData2 {
|
||||
t.Errorf("Data did not correctly update for key \"loc\"")
|
||||
}
|
||||
}
|
||||
|
@ -70,12 +77,12 @@ func TestUpdate(t *testing.T) {
|
|||
func TestAll(t *testing.T) {
|
||||
meta := NewMeta()
|
||||
tstMap := map[string]string{
|
||||
"loc": "a,b,c",
|
||||
"ts": "12345678",
|
||||
tstKey1: tstData1,
|
||||
tstKey2: tstData2,
|
||||
}
|
||||
|
||||
meta.Add("loc", "a,b,c")
|
||||
meta.Add("ts", "12345678")
|
||||
meta.Add(tstKey1, tstData1)
|
||||
meta.Add(tstKey2, tstData2)
|
||||
metaMap := meta.All()
|
||||
|
||||
if !reflect.DeepEqual(metaMap, tstMap) {
|
||||
|
@ -83,32 +90,28 @@ func TestAll(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: test get when key doesn't exist
|
||||
func TestGetAbsentKey(t *testing.T) {
|
||||
meta := NewMeta()
|
||||
|
||||
if _, err := meta.Get("loc"); err != errKeyAbsent {
|
||||
if _, err := meta.Get(tstKey1); err != errKeyAbsent {
|
||||
t.Errorf("Did not get expected err: %v", errKeyAbsent.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
meta := NewMeta()
|
||||
meta.Add("loc", "a,b,c")
|
||||
if err := meta.Delete("loc"); err != nil {
|
||||
meta.Add(tstKey1, tstData1)
|
||||
if err := meta.Delete(tstKey1); err != nil {
|
||||
t.Errorf("Did not expect error: %v", err.Error())
|
||||
}
|
||||
if _, err := meta.Get("loc"); err != errKeyAbsent {
|
||||
if _, err := meta.Get(tstKey1); err != errKeyAbsent {
|
||||
t.Errorf("Did not get expected err: %v", errKeyAbsent.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteAbsentKey(t *testing.T) {
|
||||
meta := NewMeta()
|
||||
if err := meta.Delete("loc"); err != errKeyAbsent {
|
||||
if err := meta.Delete(tstKey1); err != errKeyAbsent {
|
||||
t.Errorf("Did not get expected err: %v", errKeyAbsent.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: test delete when key exists
|
||||
// TODO: test delete when key doesn't exist
|
||||
|
|
Loading…
Reference in New Issue