Additional test coverage for point

pull/5196/head
Jonathan A. Sternberg 2016-02-01 18:10:04 -05:00 committed by Ben Johnson
parent a1cdc71ae5
commit f41070fb56
2 changed files with 149 additions and 2 deletions

View File

@ -17,11 +17,11 @@ func (v *{{.Name}}Point) name() string { return v.Name }
func (v *{{.Name}}Point) tags() Tags { return v.Tags }
func (v *{{.Name}}Point) time() int64 { return v.Time }
func (v *{{.Name}}Point) nil() bool { return v.Nil }
func (v *{{.Name}}Point) value() interface{} {
func (v *{{.Name}}Point) value() interface{} {
if v.Nil {
return nil
}
return v.Value
return v.Value
}
func (v *{{.Name}}Point) aux() []interface{} { return v.Aux }

View File

@ -6,8 +6,155 @@ import (
"testing"
"github.com/influxdb/influxdb/influxql"
"github.com/influxdb/influxdb/pkg/deep"
)
func TestPoint_Clone_Float(t *testing.T) {
p := &influxql.FloatPoint{
Name: "cpu",
Tags: ParseTags("host=server01"),
Time: 5,
Value: 2,
Aux: []interface{}{float64(45)},
}
c := p.Clone()
if p == c {
t.Errorf("clone has the same address as the original: %v == %v", p, c)
}
if p.Name != c.Name {
t.Errorf("mismatched name: %v != %v", p.Name, c.Name)
}
if !deep.Equal(p.Tags, c.Tags) {
t.Errorf("mismatched tags: %v != %v", p.Tags.ID(), c.Tags.ID())
}
if p.Time != c.Time {
t.Errorf("mismatched time: %v != %v", p.Time, c.Time)
}
if p.Value != c.Value {
t.Errorf("mismatched value: %v != %v", p.Value, c.Value)
}
if &p.Aux[0] == &c.Aux[0] {
t.Errorf("aux values share the same address: %v == %v", p.Aux, c.Aux)
} else if !deep.Equal(p.Aux, c.Aux) {
t.Errorf("mismatched aux fields: %v != %v", p.Aux, c.Aux)
}
}
func TestPoint_Clone_Integer(t *testing.T) {
p := &influxql.IntegerPoint{
Name: "cpu",
Tags: ParseTags("host=server01"),
Time: 5,
Value: 2,
Aux: []interface{}{float64(45)},
}
c := p.Clone()
if p == c {
t.Errorf("clone has the same address as the original: %v == %v", p, c)
}
if p.Name != c.Name {
t.Errorf("mismatched name: %v != %v", p.Name, c.Name)
}
if !deep.Equal(p.Tags, c.Tags) {
t.Errorf("mismatched tags: %v != %v", p.Tags.ID(), c.Tags.ID())
}
if p.Time != c.Time {
t.Errorf("mismatched time: %v != %v", p.Time, c.Time)
}
if p.Value != c.Value {
t.Errorf("mismatched value: %v != %v", p.Value, c.Value)
}
if &p.Aux[0] == &c.Aux[0] {
t.Errorf("aux values share the same address: %v == %v", p.Aux, c.Aux)
} else if !deep.Equal(p.Aux, c.Aux) {
t.Errorf("mismatched aux fields: %v != %v", p.Aux, c.Aux)
}
}
func TestPoint_Clone_String(t *testing.T) {
p := &influxql.StringPoint{
Name: "cpu",
Tags: ParseTags("host=server01"),
Time: 5,
Value: "clone",
Aux: []interface{}{float64(45)},
}
c := p.Clone()
if p == c {
t.Errorf("clone has the same address as the original: %v == %v", p, c)
}
if p.Name != c.Name {
t.Errorf("mismatched name: %v != %v", p.Name, c.Name)
}
if !deep.Equal(p.Tags, c.Tags) {
t.Errorf("mismatched tags: %v != %v", p.Tags.ID(), c.Tags.ID())
}
if p.Time != c.Time {
t.Errorf("mismatched time: %v != %v", p.Time, c.Time)
}
if p.Value != c.Value {
t.Errorf("mismatched value: %v != %v", p.Value, c.Value)
}
if &p.Aux[0] == &c.Aux[0] {
t.Errorf("aux values share the same address: %v == %v", p.Aux, c.Aux)
} else if !deep.Equal(p.Aux, c.Aux) {
t.Errorf("mismatched aux fields: %v != %v", p.Aux, c.Aux)
}
}
func TestPoint_Clone_Boolean(t *testing.T) {
p := &influxql.BooleanPoint{
Name: "cpu",
Tags: ParseTags("host=server01"),
Time: 5,
Value: true,
Aux: []interface{}{float64(45)},
}
c := p.Clone()
if p == c {
t.Errorf("clone has the same address as the original: %v == %v", p, c)
}
if p.Name != c.Name {
t.Errorf("mismatched name: %v != %v", p.Name, c.Name)
}
if !deep.Equal(p.Tags, c.Tags) {
t.Errorf("mismatched tags: %v != %v", p.Tags.ID(), c.Tags.ID())
}
if p.Time != c.Time {
t.Errorf("mismatched time: %v != %v", p.Time, c.Time)
}
if p.Value != c.Value {
t.Errorf("mismatched value: %v != %v", p.Value, c.Value)
}
if &p.Aux[0] == &c.Aux[0] {
t.Errorf("aux values share the same address: %v == %v", p.Aux, c.Aux)
} else if !deep.Equal(p.Aux, c.Aux) {
t.Errorf("mismatched aux fields: %v != %v", p.Aux, c.Aux)
}
}
func TestPoint_Clone_Nil(t *testing.T) {
var fp *influxql.FloatPoint
if p := fp.Clone(); p != nil {
t.Errorf("expected nil, got %v", p)
}
var ip *influxql.IntegerPoint
if p := ip.Clone(); p != nil {
t.Errorf("expected nil, got %v", p)
}
var sp *influxql.StringPoint
if p := sp.Clone(); p != nil {
t.Errorf("expected nil, got %v", p)
}
var bp *influxql.BooleanPoint
if p := bp.Clone(); p != nil {
t.Errorf("expected nil, got %v", p)
}
}
// Ensure that tags can return a unique id.
func TestTags_ID(t *testing.T) {
tags := influxql.NewTags(map[string]string{"foo": "bar", "baz": "bat"})