示例#1
0
// MockBatchPoints returns a mock BatchPoints object for using in unit tests
// of telegraf output sinks.
func MockBatchPoints() client.BatchPoints {
	var bp client.BatchPoints
	bp.Time = time.Now()
	bp.Tags = map[string]string{"tag1": "value1"}
	bp.Points = []client.Point{
		{
			Fields: map[string]interface{}{"value": 1.0},
		},
	}
	return bp
}
示例#2
0
func TestWrite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}

	o := &OpenTSDB{
		Host:   testutil.GetLocalHost(),
		Port:   24242,
		Prefix: "prefix.test.",
	}

	// Verify that we can connect to the OpenTSDB instance
	err := o.Connect()
	require.NoError(t, err)

	// Verify that we can successfully write data to OpenTSDB
	err = o.Write(testutil.MockBatchPoints())
	require.NoError(t, err)

	// 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)

}