From c6536b676956da7dc993b40beefb661553a3df7b Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Wed, 18 Nov 2015 23:18:28 +0000 Subject: [PATCH] Add extra test coverage; fix test typo --- models/points_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/models/points_test.go b/models/points_test.go index f11f35b167..8a1ed93099 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -231,6 +231,8 @@ func TestParsePointMissingTagKey(t *testing.T) { func TestParsePointMissingTagValue(t *testing.T) { expectedSuffix := "missing tag value" examples := []string{ + `cpu,host`, + `cpu,host,`, `cpu,host value=1i`, `cpu,host=serverA,region value=1i`, `cpu,host=serverA,region= value=1i`, @@ -247,6 +249,23 @@ func TestParsePointMissingTagValue(t *testing.T) { } } +func TestParsePointInvalidTagFormat(t *testing.T) { + expectedSuffix := "invalid tag format" + examples := []string{ + `cpu,host==`, + `cpu,host=f=o,`, + } + + for i, example := range examples { + _, err := models.ParsePointsString(example) + if err == nil { + t.Errorf(`[Example %d] ParsePoints("%s") mismatch. got nil, exp error`, i, example) + } else if !strings.HasSuffix(err.Error(), expectedSuffix) { + t.Errorf(`[Example %d] ParsePoints("%s") mismatch. got %q, exp suffix %q`, i, example, err, expectedSuffix) + } + } +} + func TestParsePointMissingFieldName(t *testing.T) { _, err := models.ParsePointsString(`cpu,host=serverA,region=us-west =`) if err == nil { @@ -1141,7 +1160,7 @@ func TestNewPointLargeNumberOfTags(t *testing.T) { } if len(pt[0].Tags()) != 255 { - t.Fatalf("ParsePoints() with max tags failed: %v", err) + t.Fatalf("expected %d tags, got %d", 255, len(pt[0].Tags())) } } @@ -1181,7 +1200,7 @@ func TestParsePointKeyUnsorted(t *testing.T) { pt := pts[0] if exp := "cpu,first=2,last=1"; string(pt.Key()) != exp { - t.Errorf("ParsePoint key not sorted. got %v, exp %v", pt.Key(), exp) + t.Errorf("ParsePoint key not sorted. got %v, exp %v", string(pt.Key()), exp) } }