stream/mts/meta/meta_test.go: adding test for ReadFrom

This commit is contained in:
saxon 2019-02-01 09:27:43 +10:30
parent 1f1546a284
commit 38d5d6f0fd
1 changed files with 25 additions and 1 deletions

View File

@ -42,6 +42,10 @@ const (
tstData3 = "d,e,f"
)
var (
errNotExpectedOut = "Did not get expected out. \nGot : %v, \nwant: %v"
)
// TestAddAndGet ensures that we can add metadata and then successfully get it.
func TestAddAndGet(t *testing.T) {
meta := New()
@ -145,6 +149,26 @@ func TestEncode(t *testing.T) {
got := meta.Encode()
if !bytes.Equal(expectedOut, got) {
t.Errorf("Did not get expected out. \nGot : %v \nwant: %v", got, expectedOut)
t.Errorf(errNotExpectedOut, got, expectedOut)
}
}
func TestReadFrom(t *testing.T) {
tstStr := "loc=a,b,c\tts=12345"
got, err := ReadFrom([]byte(tstStr), "loc")
if err != nil {
t.Errorf("Got unexpected error: %v", err.Error())
}
want := "a,b,c"
if got != want {
t.Errorf(errNotExpectedOut, got, want)
}
if got, err = ReadFrom([]byte(tstStr), "ts"); err != nil {
t.Errorf("Got unexpected error: %v", err.Error())
}
want = "12345"
if got != want {
t.Errorf(errNotExpectedOut, got, want)
}
}