stream/mts/meta/meta_test.go: created global err vars

This commit is contained in:
saxon 2019-02-01 11:17:53 +10:30
parent 38d5d6f0fd
commit 4d4a8e04ec
1 changed files with 10 additions and 8 deletions

View File

@ -43,7 +43,9 @@ const (
) )
var ( var (
errNotExpectedOut = "Did not get expected out. \nGot : %v, \nwant: %v" errNotExpectedOut = "Did not get expected out. \nGot : %v, \nwant: %v\n"
errUnexpectedErr = "Unexpected err: %v\n"
errNotExpectedErr = "Not expected err: %v\n"
) )
// TestAddAndGet ensures that we can add metadata and then successfully get it. // TestAddAndGet ensures that we can add metadata and then successfully get it.
@ -75,7 +77,7 @@ func TestUpdate(t *testing.T) {
meta.Add(tstKey1, tstData3) meta.Add(tstKey1, tstData3)
if data, err := meta.Get(tstKey1); err != nil { if data, err := meta.Get(tstKey1); err != nil {
t.Errorf("Did not expect err: %v", err.Error()) t.Errorf(errUnexpectedErr, err.Error())
if data != tstData2 { if data != tstData2 {
t.Errorf("Data did not correctly update for key \"loc\"") t.Errorf("Data did not correctly update for key \"loc\"")
} }
@ -105,7 +107,7 @@ func TestGetAbsentKey(t *testing.T) {
meta := New() meta := New()
if _, err := meta.Get(tstKey1); err != errKeyAbsent { if _, err := meta.Get(tstKey1); err != errKeyAbsent {
t.Errorf("Did not get expected err: %v", errKeyAbsent.Error()) t.Errorf(errNotExpectedErr, errKeyAbsent.Error())
} }
} }
@ -114,10 +116,10 @@ func TestDelete(t *testing.T) {
meta := New() meta := New()
meta.Add(tstKey1, tstData1) meta.Add(tstKey1, tstData1)
if err := meta.Delete(tstKey1); err != nil { if err := meta.Delete(tstKey1); err != nil {
t.Errorf("Did not expect error: %v", err.Error()) t.Errorf(errUnexpectedErr, err.Error())
} }
if _, err := meta.Get(tstKey1); err != errKeyAbsent { if _, err := meta.Get(tstKey1); err != errKeyAbsent {
t.Errorf("Did not get expected err: %v", errKeyAbsent.Error()) t.Errorf(errNotExpectedErr, errKeyAbsent.Error())
} }
} }
@ -126,7 +128,7 @@ func TestDelete(t *testing.T) {
func TestDeleteAbsentKey(t *testing.T) { func TestDeleteAbsentKey(t *testing.T) {
meta := New() meta := New()
if err := meta.Delete(tstKey1); err != errKeyAbsent { if err := meta.Delete(tstKey1); err != errKeyAbsent {
t.Errorf("Did not get expected err: %v", errKeyAbsent.Error()) t.Errorf(errNotExpectedErr, errKeyAbsent.Error())
} }
} }
@ -157,7 +159,7 @@ func TestReadFrom(t *testing.T) {
tstStr := "loc=a,b,c\tts=12345" tstStr := "loc=a,b,c\tts=12345"
got, err := ReadFrom([]byte(tstStr), "loc") got, err := ReadFrom([]byte(tstStr), "loc")
if err != nil { if err != nil {
t.Errorf("Got unexpected error: %v", err.Error()) t.Errorf(errUnexpectedErr, err.Error())
} }
want := "a,b,c" want := "a,b,c"
if got != want { if got != want {
@ -165,7 +167,7 @@ func TestReadFrom(t *testing.T) {
} }
if got, err = ReadFrom([]byte(tstStr), "ts"); err != nil { if got, err = ReadFrom([]byte(tstStr), "ts"); err != nil {
t.Errorf("Got unexpected error: %v", err.Error()) t.Errorf(errUnexpectedErr, err.Error())
} }
want = "12345" want = "12345"
if got != want { if got != want {