2015-09-10 18:35:12 +00:00
|
|
|
package opentsdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2015-10-16 22:13:32 +00:00
|
|
|
"github.com/influxdb/influxdb/client/v2"
|
2015-09-13 20:35:38 +00:00
|
|
|
"github.com/influxdb/telegraf/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
2015-09-10 18:35:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuildTagsTelnet(t *testing.T) {
|
|
|
|
var tagtests = []struct {
|
|
|
|
ptIn map[string]string
|
|
|
|
outTags []string
|
|
|
|
}{
|
|
|
|
{
|
2015-10-16 22:13:32 +00:00
|
|
|
map[string]string{"one": "two", "three": "four"},
|
2015-09-10 18:35:12 +00:00
|
|
|
[]string{"one=two", "three=four"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
map[string]string{"aaa": "bbb"},
|
|
|
|
[]string{"aaa=bbb"},
|
|
|
|
},
|
|
|
|
{
|
2015-10-16 22:13:32 +00:00
|
|
|
map[string]string{"one": "two", "aaa": "bbb"},
|
2015-09-10 18:35:12 +00:00
|
|
|
[]string{"aaa=bbb", "one=two"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
map[string]string{},
|
|
|
|
[]string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tagtests {
|
2015-10-16 22:13:32 +00:00
|
|
|
tags := buildTags(tt.ptIn)
|
2015-09-10 18:35:12 +00:00
|
|
|
if !reflect.DeepEqual(tags, tt.outTags) {
|
|
|
|
t.Errorf("\nexpected %+v\ngot %+v\n", tt.outTags, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-16 22:13:32 +00:00
|
|
|
|
2015-09-11 20:24:53 +00:00
|
|
|
func TestWrite(t *testing.T) {
|
2015-09-13 20:35:38 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
2015-09-11 20:24:53 +00:00
|
|
|
|
2015-09-13 20:35:38 +00:00
|
|
|
o := &OpenTSDB{
|
|
|
|
Host: testutil.GetLocalHost(),
|
|
|
|
Port: 24242,
|
|
|
|
Prefix: "prefix.test.",
|
|
|
|
}
|
2015-09-11 20:24:53 +00:00
|
|
|
|
2015-09-13 20:35:38 +00:00
|
|
|
// Verify that we can connect to the OpenTSDB instance
|
|
|
|
err := o.Connect()
|
|
|
|
require.NoError(t, err)
|
2015-09-11 20:24:53 +00:00
|
|
|
|
2015-09-13 20:35:38 +00:00
|
|
|
// Verify that we can successfully write data to OpenTSDB
|
2015-10-16 22:13:32 +00:00
|
|
|
err = o.Write(testutil.MockBatchPoints().Points())
|
2015-09-13 20:35:38 +00:00
|
|
|
require.NoError(t, err)
|
2015-09-14 10:28:10 +00:00
|
|
|
|
|
|
|
// Verify postive and negative test cases of writing data
|
2015-10-16 22:13:32 +00:00
|
|
|
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)}))
|
|
|
|
|
|
|
|
err = o.Write(bp.Points())
|
2015-09-14 10:28:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2015-09-11 20:24:53 +00:00
|
|
|
}
|