From 66a2325dcb659b179585f4ab34130654366f0250 Mon Sep 17 00:00:00 2001 From: saxon Date: Thu, 7 Feb 2019 10:42:01 +1030 Subject: [PATCH] stream/mts/meta/meta_test.go: using table of tests for TestReadFrom --- stream/mts/meta/meta_test.go | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/stream/mts/meta/meta_test.go b/stream/mts/meta/meta_test.go index 2be41b95..002bbc8f 100644 --- a/stream/mts/meta/meta_test.go +++ b/stream/mts/meta/meta_test.go @@ -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") - 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) + + tests := []struct { + key string + want string + }{ + { + "loc", + "a,b,c", + }, + { + "ts", + "12345", + }, } - 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) + for _, test := range tests { + got, err := ReadFrom([]byte(tstMeta), test.key) + if err != nil { + t.Errorf("Unexpected err: %v\n", err) + } + if got != test.want { + t.Errorf("Did not get expected out. \nGot : %v, \nwant: %v\n", got, test.want) + } } }