diff --git a/models/points_test.go b/models/points_test.go index db3065ae338..b8afae9ee5c 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -1772,3 +1772,27 @@ t159,label=another a=2i,value=1i 1` t.Fatalf("expected 2 points, got %d", len(points)) } } + +func TestNewPointsWithBytesWithCorruptData(t *testing.T) { + ch := make(chan error) + go func() { + corrupted := []byte{0, 0, 0, 3, 102, 111, 111, 0, 0, 0, 4, 61, 34, 65, 34, 1, 0, 0, 0, 14, 206, 86, 119, 24, 32, 72, 233, 168, 2, 148} + p, err := models.NewPointFromBytes(corrupted) + p.Fields() // this method should always return, even if the data is corrupt. + ch <- err + }() + select { + case err := <-ch: + if err != nil { + t.Fatalf("unexpected error: got: %v, expected: nil", err) + } + case _ = <-time.NewTimer(time.Second).C: + t.Fatalf("probable infite loop. got: timeout, expected: return") + } +} + +func TestNewPointsRejectsEmptyFieldNames(t *testing.T) { + if _, err := models.NewPoint("foo", nil, models.Fields{"": 1}, time.Now()); err == nil { + t.Fatalf("new point with empty field name. got: nil, expected: error") + } +}