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