mirror of https://bitbucket.org/ausocean/av.git
Merged in meta-more-unit-tests (pull request #381)
add unit tests for NewFromMap and EncodeAsString methods Approved-by: Saxon Milton <saxon.milton@gmail.com>
This commit is contained in:
commit
d996635232
|
@ -216,3 +216,77 @@ func TestKeys(t *testing.T) {
|
||||||
t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v\n", got, want)
|
t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v\n", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestNewFromMap checks that we can successfully create a new data struct from a map.
|
||||||
|
func TestNewFromMap(t *testing.T) {
|
||||||
|
want := map[string]string{
|
||||||
|
"loc": "a,b,c",
|
||||||
|
"ts": "12345",
|
||||||
|
}
|
||||||
|
|
||||||
|
meta := NewFromMap(want)
|
||||||
|
|
||||||
|
got := meta.All()
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v\n", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestEncodeAsString checks that metadata is correctly encoded as a string.
|
||||||
|
func TestEncodeAsString(t *testing.T) {
|
||||||
|
meta := NewFromMap(map[string]string{
|
||||||
|
"loc": "a,b,c",
|
||||||
|
"ts": "12345",
|
||||||
|
})
|
||||||
|
|
||||||
|
got := meta.EncodeAsString()
|
||||||
|
want1 := "loc=a,b,c\tts=12345"
|
||||||
|
want2 := "ts=12345\tloc=a,b,c"
|
||||||
|
|
||||||
|
if got != want1 && got != want2 {
|
||||||
|
t.Errorf("Did not get expected out. \nGot : %v, \nWant: %v or %v\n", got, want1, want2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestDeleteOrder checks that the order of keys is correct after a deletion.
|
||||||
|
func TestDeleteOrder(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
delKey string
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"key1",
|
||||||
|
[]string{"key2", "key3", "key4"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key2",
|
||||||
|
[]string{"key1", "key3", "key4"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key3",
|
||||||
|
[]string{"key1", "key2", "key4"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key4",
|
||||||
|
[]string{"key1", "key2", "key3"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Logf("deleting %s", test.delKey)
|
||||||
|
meta := NewWith([][2]string{
|
||||||
|
{"key1", "val1"},
|
||||||
|
{"key2", "val2"},
|
||||||
|
{"key3", "val3"},
|
||||||
|
{"key4", "val4"},
|
||||||
|
})
|
||||||
|
meta.Delete(test.delKey)
|
||||||
|
|
||||||
|
got := meta.order
|
||||||
|
want := test.want
|
||||||
|
if !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("Did not get expected out. \nGot: %v, \nWant: %v\n", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue