Skip to content

Commit

Permalink
models: add tests for point construction
Browse files Browse the repository at this point in the history
These tests check that NewPoint and NewPointFromBytes return an error if:

* arguments specify a point with no fields
* arguments specify a point with a field that has an empty name

These tests also check that Point.Fields() always returns, even in the presence
of corrupt binary data read with NewPointFromBytes.

These tests fail at this commit and are fixed by a subsequent commit.

Signed-off-by: Jon Seymour <jon@wildducktheories.com>
  • Loading branch information
jonseymour committed Feb 19, 2016
1 parent 88937ab commit bfb361e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions models/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit bfb361e

Please sign in to comment.