2015-11-06 09:27:17 +00:00
|
|
|
package amon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-01-20 18:57:35 +00:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2015-11-06 09:27:17 +00:00
|
|
|
|
2016-01-27 23:15:14 +00:00
|
|
|
"github.com/influxdata/telegraf"
|
2015-11-06 09:27:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildPoint(t *testing.T) {
|
|
|
|
var tagtests = []struct {
|
2016-01-27 23:15:14 +00:00
|
|
|
ptIn telegraf.Metric
|
2015-11-06 09:27:17 +00:00
|
|
|
outPt Point
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric(float64(0.0), "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
|
|
|
0.0,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric(float64(1.0), "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
2015-11-11 00:05:28 +00:00
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
2015-11-06 09:27:17 +00:00
|
|
|
1.0,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric(int(10), "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
|
|
|
10.0,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric(int32(112345), "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
|
|
|
112345.0,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric(int64(112345), "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
|
|
|
112345.0,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric(float32(11234.5), "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
|
|
|
11234.5,
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
2016-01-27 23:15:14 +00:00
|
|
|
testutil.TestMetric("11234.5", "testpt"),
|
2015-11-06 09:27:17 +00:00
|
|
|
Point{
|
|
|
|
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
|
|
|
11234.5,
|
|
|
|
},
|
|
|
|
fmt.Errorf("unable to extract value from Fields, undeterminable type"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tagtests {
|
2016-01-27 23:15:14 +00:00
|
|
|
pt, err := buildMetrics(tt.ptIn)
|
2015-11-06 09:27:17 +00:00
|
|
|
if err != nil && tt.err == nil {
|
|
|
|
t.Errorf("%s: unexpected error, %+v\n", tt.ptIn.Name(), err)
|
|
|
|
}
|
|
|
|
if tt.err != nil && err == nil {
|
|
|
|
t.Errorf("%s: expected an error (%s) but none returned", tt.ptIn.Name(), tt.err.Error())
|
|
|
|
}
|
2016-01-07 17:09:04 +00:00
|
|
|
if !reflect.DeepEqual(pt["value"], tt.outPt) && tt.err == nil {
|
|
|
|
t.Errorf("%s: \nexpected %+v\ngot %+v\n",
|
|
|
|
tt.ptIn.Name(), tt.outPt, pt["value"])
|
2015-11-06 09:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|