test(models): don't reassign package variable

Prior to this change, `go test -count=2 ./models` would fail like:

--- FAIL: TestMarshal (0.00s)
    points_test.go:37: got:  ,A\ FOO=bar,APPLE=orange,host=serverA,region=uswest
    points_test.go:38: exp:  ,apple=orange,foo=bar,host=serverA,region=uswest
    points_test.go:39: invalid match

because a later test reassigned the package-level variable that
TestMarshal depends on. Don't reassign that variable anymore.

Also cleaned up some whitespace, and moved an init function to the top
of the file for visibility.
pull/10616/head
Mark Rushakoff 2018-11-09 14:39:49 -08:00 committed by Mark Rushakoff
parent 2f8893f5d5
commit ed4bba83f5
1 changed files with 7 additions and 10 deletions

View File

@ -15,6 +15,11 @@ import (
"github.com/influxdata/platform/models" "github.com/influxdata/platform/models"
) )
func init() {
// Force uint support to be enabled for testing.
models.EnableUintSupport()
}
var ( var (
tags = models.NewTags(map[string]string{"foo": "bar", "apple": "orange", "host": "serverA", "region": "uswest"}) tags = models.NewTags(map[string]string{"foo": "bar", "apple": "orange", "host": "serverA", "region": "uswest"})
fields = models.Fields{ fields = models.Fields{
@ -82,7 +87,7 @@ func TestMarshalFields(t *testing.T) {
} }
func TestTags_HashKey(t *testing.T) { func TestTags_HashKey(t *testing.T) {
tags = models.NewTags(map[string]string{"A FOO": "bar", "APPLE": "orange", "host": "serverA", "region": "uswest"}) tags := models.NewTags(map[string]string{"A FOO": "bar", "APPLE": "orange", "host": "serverA", "region": "uswest"})
got := tags.HashKey() got := tags.HashKey()
if exp := ",A\\ FOO=bar,APPLE=orange,host=serverA,region=uswest"; string(got) != exp { if exp := ",A\\ FOO=bar,APPLE=orange,host=serverA,region=uswest"; string(got) != exp {
t.Log("got: ", string(got)) t.Log("got: ", string(got))
@ -96,6 +101,7 @@ func BenchmarkMarshal(b *testing.B) {
tags.HashKey() tags.HashKey()
} }
} }
func TestPoint_Tags(t *testing.T) { func TestPoint_Tags(t *testing.T) {
examples := []struct { examples := []struct {
Point string Point string
@ -128,7 +134,6 @@ func TestPoint_Tags(t *testing.T) {
t.Fatalf("got %#v (%s), expected %#v", tags, tags.String(), example.Tags) t.Fatalf("got %#v (%s), expected %#v", tags, tags.String(), example.Tags)
} }
} }
}) })
} }
} }
@ -142,7 +147,6 @@ func TestPoint_StringSize(t *testing.T) {
t.Errorf("Incorrect length for %q. got %v, exp %v", s, l, len(s)) t.Errorf("Incorrect length for %q. got %v, exp %v", s, l, len(s))
} }
}) })
} }
func TestPoint_AppendString(t *testing.T) { func TestPoint_AppendString(t *testing.T) {
@ -2257,7 +2261,6 @@ func TestNewPointsRejectsMaxKey(t *testing.T) {
} }
func TestPoint_FieldIterator_Simple(t *testing.T) { func TestPoint_FieldIterator_Simple(t *testing.T) {
p, err := models.ParsePoints([]byte(`m v=42i,f=42 36`)) p, err := models.ParsePoints([]byte(`m v=42i,f=42 36`))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -2336,7 +2339,6 @@ func toFields(fi models.FieldIterator) models.Fields {
} }
func TestPoint_FieldIterator_FieldMap(t *testing.T) { func TestPoint_FieldIterator_FieldMap(t *testing.T) {
points, err := models.ParsePointsString(` points, err := models.ParsePointsString(`
m v=42 m v=42
m v=42i m v=42i
@ -2544,8 +2546,3 @@ func BenchmarkMakeKey(b *testing.B) {
}) })
} }
} }
func init() {
// Force uint support to be enabled for testing.
models.EnableUintSupport()
}