2015-09-10 18:35:12 +00:00
|
|
|
package opentsdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-20 20:19:03 +00:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2015-09-13 20:35:38 +00:00
|
|
|
"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(),
|
2015-10-23 15:36:30 +00:00
|
|
|
Port: 4242,
|
2015-09-13 20:35:38 +00:00
|
|
|
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()
|
2015-11-11 00:05:28 +00:00
|
|
|
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"))
|
2015-10-16 22:13:32 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|