Fix new error return of client.NewPoint
This commit is contained in:
parent
92fb51026a
commit
352ccde52b
|
@ -50,19 +50,13 @@ func TestAuthenticatedUrl(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildPoint(t *testing.T) {
|
||||
tags := make(map[string]string)
|
||||
var tagtests = []struct {
|
||||
ptIn *client.Point
|
||||
outPt Point
|
||||
err error
|
||||
}{
|
||||
{
|
||||
client.NewPoint(
|
||||
"test1",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(float64(0.0)),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
0.0,
|
||||
|
@ -70,25 +64,15 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test2",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0},
|
||||
time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(float64(1.0)),
|
||||
Point{
|
||||
float64(time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
1.0,
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test3",
|
||||
tags,
|
||||
map[string]interface{}{"value": 10},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int(10)),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
10.0,
|
||||
|
@ -96,12 +80,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test4",
|
||||
tags,
|
||||
map[string]interface{}{"value": int32(112345)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int32(112345)),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
112345.0,
|
||||
|
@ -109,12 +88,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test5",
|
||||
tags,
|
||||
map[string]interface{}{"value": int64(112345)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int64(112345)),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
112345.0,
|
||||
|
@ -122,12 +96,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test6",
|
||||
tags,
|
||||
map[string]interface{}{"value": float32(11234.5)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(float32(11234.5)),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
11234.5,
|
||||
|
@ -135,12 +104,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test7",
|
||||
tags,
|
||||
map[string]interface{}{"value": "11234.5"},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint("11234.5"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
11234.5,
|
||||
|
|
|
@ -99,19 +99,13 @@ func TestBuildTags(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildPoint(t *testing.T) {
|
||||
tags := make(map[string]string)
|
||||
var tagtests = []struct {
|
||||
ptIn *client.Point
|
||||
outPt Point
|
||||
err error
|
||||
}{
|
||||
{
|
||||
client.NewPoint(
|
||||
"test1",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(0.0, "test1"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
0.0,
|
||||
|
@ -119,25 +113,15 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test2",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0},
|
||||
time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(1.0, "test2"),
|
||||
Point{
|
||||
float64(time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
1.0,
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test3",
|
||||
tags,
|
||||
map[string]interface{}{"value": 10},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(10, "test3"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
10.0,
|
||||
|
@ -145,12 +129,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test4",
|
||||
tags,
|
||||
map[string]interface{}{"value": int32(112345)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int32(112345), "test4"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
112345.0,
|
||||
|
@ -158,12 +137,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test5",
|
||||
tags,
|
||||
map[string]interface{}{"value": int64(112345)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int64(112345), "test5"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
112345.0,
|
||||
|
@ -171,12 +145,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test6",
|
||||
tags,
|
||||
map[string]interface{}{"value": float32(11234.5)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(float32(11234.5), "test6"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
11234.5,
|
||||
|
@ -184,12 +153,7 @@ func TestBuildPoint(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test7",
|
||||
tags,
|
||||
map[string]interface{}{"value": "11234.5"},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint("11234.5", "test7"),
|
||||
Point{
|
||||
float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()),
|
||||
11234.5,
|
||||
|
|
|
@ -70,47 +70,31 @@ func TestBadStatusCode(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildGauge(t *testing.T) {
|
||||
tags := make(map[string]string)
|
||||
var gaugeTests = []struct {
|
||||
ptIn *client.Point
|
||||
outGauge *Gauge
|
||||
err error
|
||||
}{
|
||||
{
|
||||
client.NewPoint(
|
||||
"test1",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0},
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(0.0, "test1"),
|
||||
&Gauge{
|
||||
Name: "test1",
|
||||
MeasureTime: time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
Value: 0.0,
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test2",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0},
|
||||
time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(1.0, "test2"),
|
||||
&Gauge{
|
||||
Name: "test2",
|
||||
MeasureTime: time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
Value: 1.0,
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test3",
|
||||
tags,
|
||||
map[string]interface{}{"value": 10},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(10, "test3"),
|
||||
&Gauge{
|
||||
Name: "test3",
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
@ -119,12 +103,7 @@ func TestBuildGauge(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test4",
|
||||
tags,
|
||||
map[string]interface{}{"value": int32(112345)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int32(112345), "test4"),
|
||||
&Gauge{
|
||||
Name: "test4",
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
@ -133,12 +112,7 @@ func TestBuildGauge(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test5",
|
||||
tags,
|
||||
map[string]interface{}{"value": int64(112345)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(int64(112345), "test5"),
|
||||
&Gauge{
|
||||
Name: "test5",
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
@ -147,12 +121,7 @@ func TestBuildGauge(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test6",
|
||||
tags,
|
||||
map[string]interface{}{"value": float32(11234.5)},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint(float32(11234.5), "test6"),
|
||||
&Gauge{
|
||||
Name: "test6",
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
@ -161,12 +130,7 @@ func TestBuildGauge(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test7",
|
||||
tags,
|
||||
map[string]interface{}{"value": "11234.5"},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
testutil.TestPoint("11234.5", "test7"),
|
||||
&Gauge{
|
||||
Name: "test7",
|
||||
MeasureTime: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
@ -192,18 +156,26 @@ func TestBuildGauge(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBuildGaugeWithSource(t *testing.T) {
|
||||
pt1, _ := client.NewPoint(
|
||||
"test1",
|
||||
map[string]string{"hostname": "192.168.0.1"},
|
||||
map[string]interface{}{"value": 0.0},
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
)
|
||||
pt2, _ := client.NewPoint(
|
||||
"test2",
|
||||
map[string]string{"hostnam": "192.168.0.1"},
|
||||
map[string]interface{}{"value": 1.0},
|
||||
time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC),
|
||||
)
|
||||
var gaugeTests = []struct {
|
||||
ptIn *client.Point
|
||||
outGauge *Gauge
|
||||
err error
|
||||
}{
|
||||
|
||||
{
|
||||
client.NewPoint(
|
||||
"test1",
|
||||
map[string]string{"hostname": "192.168.0.1"},
|
||||
map[string]interface{}{"value": 0.0},
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
pt1,
|
||||
&Gauge{
|
||||
Name: "test1",
|
||||
MeasureTime: time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
@ -213,12 +185,7 @@ func TestBuildGaugeWithSource(t *testing.T) {
|
|||
nil,
|
||||
},
|
||||
{
|
||||
client.NewPoint(
|
||||
"test2",
|
||||
map[string]string{"hostnam": "192.168.0.1"},
|
||||
map[string]interface{}{"value": 1.0},
|
||||
time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC),
|
||||
),
|
||||
pt2,
|
||||
&Gauge{
|
||||
Name: "test2",
|
||||
MeasureTime: time.Date(2010, time.December, 10, 23, 0, 0, 0, time.UTC).Unix(),
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
"github.com/influxdb/telegraf/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -60,17 +59,11 @@ func TestWrite(t *testing.T) {
|
|||
|
||||
// Verify postive and negative test cases of writing data
|
||||
bp := testutil.MockBatchPoints()
|
||||
tags := make(map[string]string)
|
||||
bp.AddPoint(client.NewPoint("justametric.float", tags,
|
||||
map[string]interface{}{"value": float64(1.0)}))
|
||||
bp.AddPoint(client.NewPoint("justametric.int", tags,
|
||||
map[string]interface{}{"value": int64(123456789)}))
|
||||
bp.AddPoint(client.NewPoint("justametric.uint", tags,
|
||||
map[string]interface{}{"value": uint64(123456789012345)}))
|
||||
bp.AddPoint(client.NewPoint("justametric.string", tags,
|
||||
map[string]interface{}{"value": "Lorem Ipsum"}))
|
||||
bp.AddPoint(client.NewPoint("justametric.anotherfloat", tags,
|
||||
map[string]interface{}{"value": float64(42.0)}))
|
||||
bp.AddPoint(testutil.TestPoint(float64(1.0), "justametric.float"))
|
||||
bp.AddPoint(testutil.TestPoint(int64(123456789), "justametric.int"))
|
||||
bp.AddPoint(testutil.TestPoint(uint64(123456789012345), "justametric.uint"))
|
||||
bp.AddPoint(testutil.TestPoint("Lorem Ipsum", "justametric.string"))
|
||||
bp.AddPoint(testutil.TestPoint(float64(42.0), "justametric.anotherfloat"))
|
||||
|
||||
err = o.Write(bp.Points())
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -18,15 +18,17 @@ func TestPrometheusWritePointEmptyTag(t *testing.T) {
|
|||
Urls: []string{"http://localhost:9126/metrics"},
|
||||
}
|
||||
tags := make(map[string]string)
|
||||
pt1, _ := client.NewPoint(
|
||||
"test_point_1",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0})
|
||||
pt2, _ := client.NewPoint(
|
||||
"test_point_2",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0})
|
||||
var points = []*client.Point{
|
||||
client.NewPoint(
|
||||
"test_point_1",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0}),
|
||||
client.NewPoint(
|
||||
"test_point_2",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0}),
|
||||
pt1,
|
||||
pt2,
|
||||
}
|
||||
require.NoError(t, pTesting.Write(points))
|
||||
|
||||
|
@ -54,15 +56,17 @@ func TestPrometheusWritePointTag(t *testing.T) {
|
|||
}
|
||||
tags := make(map[string]string)
|
||||
tags["testtag"] = "testvalue"
|
||||
pt1, _ := client.NewPoint(
|
||||
"test_point_3",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0})
|
||||
pt2, _ := client.NewPoint(
|
||||
"test_point_4",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0})
|
||||
var points = []*client.Point{
|
||||
client.NewPoint(
|
||||
"test_point_3",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0}),
|
||||
client.NewPoint(
|
||||
"test_point_4",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0}),
|
||||
pt1,
|
||||
pt2,
|
||||
}
|
||||
require.NoError(t, pTesting.Write(points))
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
)
|
||||
|
@ -35,12 +36,29 @@ func GetLocalHost() string {
|
|||
func MockBatchPoints() client.BatchPoints {
|
||||
// Create a new point batch
|
||||
bp, _ := client.NewBatchPoints(client.BatchPointsConfig{})
|
||||
|
||||
// Create a point and add to batch
|
||||
tags := map[string]string{"tag1": "value1"}
|
||||
fields := map[string]interface{}{"value": 1.0}
|
||||
pt, _ := client.NewPoint("test_point", tags, fields)
|
||||
bp.AddPoint(pt)
|
||||
|
||||
bp.AddPoint(TestPoint(1.0))
|
||||
return bp
|
||||
}
|
||||
|
||||
// TestPoint Returns a simple test point:
|
||||
// measurement -> "test1" or name
|
||||
// tags -> "tag1":"value1"
|
||||
// value -> value
|
||||
// time -> time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
func TestPoint(value interface{}, name ...string) *client.Point {
|
||||
if value == nil {
|
||||
panic("Cannot use a nil value")
|
||||
}
|
||||
measurement := "test1"
|
||||
if len(name) > 0 {
|
||||
measurement = name[0]
|
||||
}
|
||||
tags := map[string]string{"tag1": "value1"}
|
||||
pt, _ := client.NewPoint(
|
||||
measurement,
|
||||
tags,
|
||||
map[string]interface{}{"value": value},
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
)
|
||||
return pt
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue