add unit tests for NewFromMap and EncodeAsString methods

This commit is contained in:
Scott 2020-02-25 16:53:34 +10:30
parent 813c1d38e7
commit 9a9dba0cd2
1 changed files with 32 additions and 0 deletions

View File

@ -219,3 +219,35 @@ 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)
}
}