stream/mts/meta/meta_test.go: using table of tests for TestReadFrom

This commit is contained in:
saxon 2019-02-07 10:42:01 +10:30
parent f96f761b2f
commit 66a2325dcb
1 changed files with 21 additions and 13 deletions

View File

@ -151,20 +151,28 @@ func TestEncode(t *testing.T) {
// from a string of metadata using the ReadFrom func.
func TestReadFrom(t *testing.T) {
tstMeta := append([]byte{0x00, 0x10, 0x00, 0x12}, "loc=a,b,c\tts=12345"...)
got, err := ReadFrom([]byte(tstMeta), "loc")
tests := []struct {
key string
want string
}{
{
"loc",
"a,b,c",
},
{
"ts",
"12345",
},
}
for _, test := range tests {
got, err := ReadFrom([]byte(tstMeta), test.key)
if err != nil {
t.Errorf("Unexpected err: %v\n", err)
}
want := "a,b,c"
if got != want {
t.Errorf("Did not get expected out. \nGot : %v, \nwant: %v\n", got, want)
if got != test.want {
t.Errorf("Did not get expected out. \nGot : %v, \nwant: %v\n", got, test.want)
}
if got, err = ReadFrom([]byte(tstMeta), "ts"); err != nil {
t.Errorf("Unexpected err: %v\n", err)
}
want = "12345"
if got != want {
t.Errorf("Did not get expected out. \nGot : %v, \nwant: %v\n", got, want)
}
}