2015-09-10 18:35:12 +00:00
|
|
|
package opentsdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2016-06-07 09:13:14 +00:00
|
|
|
// "github.com/influxdata/telegraf/testutil"
|
|
|
|
// "github.com/stretchr/testify/require"
|
2015-09-10 18:35:12 +00:00
|
|
|
)
|
|
|
|
|
2016-07-21 13:54:09 +00:00
|
|
|
func TestCleanTags(t *testing.T) {
|
2015-09-10 18:35:12 +00:00
|
|
|
var tagtests = []struct {
|
|
|
|
ptIn map[string]string
|
2016-07-21 13:54:09 +00:00
|
|
|
outTags TagSet
|
2015-09-10 18:35:12 +00:00
|
|
|
}{
|
|
|
|
{
|
2015-10-16 22:13:32 +00:00
|
|
|
map[string]string{"one": "two", "three": "four"},
|
2016-07-21 13:54:09 +00:00
|
|
|
TagSet{"one": "two", "three": "four"},
|
2015-09-10 18:35:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
map[string]string{"aaa": "bbb"},
|
2016-07-21 13:54:09 +00:00
|
|
|
TagSet{"aaa": "bbb"},
|
2015-09-10 18:35:12 +00:00
|
|
|
},
|
2016-04-28 23:00:06 +00:00
|
|
|
{
|
|
|
|
map[string]string{"Sp%ci@l Chars": "g$t repl#ced"},
|
2016-07-21 13:54:09 +00:00
|
|
|
TagSet{"Sp-ci-l_Chars": "g-t_repl-ced"},
|
2016-04-28 23:00:06 +00:00
|
|
|
},
|
2015-09-10 18:35:12 +00:00
|
|
|
{
|
|
|
|
map[string]string{},
|
2016-07-21 13:54:09 +00:00
|
|
|
TagSet{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tagtests {
|
|
|
|
tags := cleanTags(tt.ptIn)
|
|
|
|
if !reflect.DeepEqual(tags, tt.outTags) {
|
|
|
|
t.Errorf("\nexpected %+v\ngot %+v\n", tt.outTags, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuildTagsTelnet(t *testing.T) {
|
|
|
|
var tagtests = []struct {
|
|
|
|
ptIn TagSet
|
|
|
|
outTags string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
TagSet{"one": "two", "three": "four"},
|
|
|
|
"one=two three=four",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TagSet{"aaa": "bbb"},
|
|
|
|
"aaa=bbb",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TagSet{"one": "two", "aaa": "bbb"},
|
|
|
|
"aaa=bbb one=two",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TagSet{},
|
|
|
|
"",
|
2015-09-10 18:35:12 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tagtests {
|
2016-07-21 13:54:09 +00:00
|
|
|
tags := tt.ptIn.ToLineFormat()
|
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
|
|
|
|
2016-06-07 09:13:14 +00:00
|
|
|
// func TestWrite(t *testing.T) {
|
|
|
|
// if testing.Short() {
|
|
|
|
// t.Skip("Skipping integration test in short mode")
|
|
|
|
// }
|
2015-09-11 20:24:53 +00:00
|
|
|
|
2016-06-07 09:13:14 +00:00
|
|
|
// o := &OpenTSDB{
|
|
|
|
// Host: testutil.GetLocalHost(),
|
|
|
|
// Port: 4242,
|
|
|
|
// Prefix: "prefix.test.",
|
|
|
|
// }
|
2015-09-11 20:24:53 +00:00
|
|
|
|
2016-06-07 09:13:14 +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
|
|
|
|
2016-06-07 09:13:14 +00:00
|
|
|
// // Verify that we can successfully write data to OpenTSDB
|
|
|
|
// err = o.Write(testutil.MockMetrics())
|
|
|
|
// require.NoError(t, err)
|
2015-09-14 10:28:10 +00:00
|
|
|
|
2016-06-07 09:13:14 +00:00
|
|
|
// // Verify postive and negative test cases of writing data
|
|
|
|
// metrics := testutil.MockMetrics()
|
|
|
|
// metrics = append(metrics, testutil.TestMetric(float64(1.0),
|
|
|
|
// "justametric.float"))
|
|
|
|
// metrics = append(metrics, testutil.TestMetric(int64(123456789),
|
|
|
|
// "justametric.int"))
|
|
|
|
// metrics = append(metrics, testutil.TestMetric(uint64(123456789012345),
|
|
|
|
// "justametric.uint"))
|
|
|
|
// metrics = append(metrics, testutil.TestMetric("Lorem Ipsum",
|
|
|
|
// "justametric.string"))
|
|
|
|
// metrics = append(metrics, testutil.TestMetric(float64(42.0),
|
|
|
|
// "justametric.anotherfloat"))
|
|
|
|
// metrics = append(metrics, testutil.TestMetric(float64(42.0),
|
|
|
|
// "metric w/ specialchars"))
|
2015-10-16 22:13:32 +00:00
|
|
|
|
2016-06-07 09:13:14 +00:00
|
|
|
// err = o.Write(metrics)
|
|
|
|
// require.NoError(t, err)
|
|
|
|
// }
|