2015-09-10 18:35:12 +00:00
|
|
|
package opentsdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2015-09-14 10:28:10 +00:00
|
|
|
"time"
|
2015-09-10 18:35:12 +00:00
|
|
|
|
2015-09-14 10:28:10 +00:00
|
|
|
"github.com/influxdb/influxdb/client"
|
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 {
|
|
|
|
bpIn map[string]string
|
|
|
|
ptIn map[string]string
|
|
|
|
outTags []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
map[string]string{"one": "two"},
|
|
|
|
map[string]string{"three": "four"},
|
|
|
|
[]string{"one=two", "three=four"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
map[string]string{"aaa": "bbb"},
|
|
|
|
map[string]string{},
|
|
|
|
[]string{"aaa=bbb"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
map[string]string{"one": "two"},
|
|
|
|
map[string]string{"aaa": "bbb"},
|
|
|
|
[]string{"aaa=bbb", "one=two"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
map[string]string{},
|
|
|
|
map[string]string{},
|
|
|
|
[]string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tagtests {
|
|
|
|
tags := buildTags(tt.bpIn, tt.ptIn)
|
|
|
|
if !reflect.DeepEqual(tags, tt.outTags) {
|
|
|
|
t.Errorf("\nexpected %+v\ngot %+v\n", tt.outTags, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
err = o.Write(testutil.MockBatchPoints())
|
|
|
|
require.NoError(t, err)
|
2015-09-14 10:28:10 +00:00
|
|
|
|
|
|
|
// Verify postive and negative test cases of writing data
|
|
|
|
var bp client.BatchPoints
|
|
|
|
bp.Time = time.Now()
|
|
|
|
bp.Tags = map[string]string{"testkey": "testvalue"}
|
|
|
|
bp.Points = []client.Point{
|
|
|
|
{
|
|
|
|
Measurement: "justametric.float",
|
|
|
|
Fields: map[string]interface{}{"value": float64(1.0)},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Measurement: "justametric.int",
|
|
|
|
Fields: map[string]interface{}{"value": int64(123456789)},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Measurement: "justametric.uint",
|
|
|
|
Fields: map[string]interface{}{"value": uint64(123456789012345)},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Measurement: "justametric.string",
|
|
|
|
Fields: map[string]interface{}{"value": "Lorem Ipsum"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Measurement: "justametric.anotherfloat",
|
|
|
|
Fields: map[string]interface{}{"value": float64(42.0)},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err = o.Write(bp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2015-09-11 20:24:53 +00:00
|
|
|
}
|