func TestFileNewFile(t *testing.T) { s, _ := serializers.NewInfluxSerializer() fh := tmpFile() f := File{ Files: []string{fh}, serializer: s, } err := f.Connect() assert.NoError(t, err) err = f.Write(testutil.MockMetrics()) assert.NoError(t, err) validateFile(fh, expNewFile, t) err = f.Close() assert.NoError(t, err) }
func TestFileExistingFile(t *testing.T) { fh := createFile() s, _ := serializers.NewInfluxSerializer() f := File{ Files: []string{fh.Name()}, serializer: s, } err := f.Connect() assert.NoError(t, err) err = f.Write(testutil.MockMetrics()) assert.NoError(t, err) validateFile(fh.Name(), expExistFile, t) err = f.Close() assert.NoError(t, err) }
func TestConnectAndWrite(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } var url = testutil.GetLocalHost() + ":1883" s, _ := serializers.NewInfluxSerializer() m := &MQTT{ Servers: []string{url}, serializer: s, } // Verify that we can connect to the MQTT broker err := m.Connect() require.NoError(t, err) // Verify that we can successfully write data to the mqtt broker err = m.Write(testutil.MockMetrics()) require.NoError(t, err) }
func TestConnectAndWrite(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } var url = "amqp://" + testutil.GetLocalHost() + ":5672/" s, _ := serializers.NewInfluxSerializer() q := &AMQP{ URL: url, Exchange: "telegraf_test", serializer: s, } // Verify that we can connect to the AMQP broker err := q.Connect() require.NoError(t, err) // Verify that we can successfully write data to the amqp broker err = q.Write(testutil.MockMetrics()) require.NoError(t, err) }
func TestConnectAndWrite(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } brokers := []string{testutil.GetLocalHost() + ":9092"} s, _ := serializers.NewInfluxSerializer() k := &Kafka{ Brokers: brokers, Topic: "Test", serializer: s, } // Verify that we can connect to the Kafka broker err := k.Connect() require.NoError(t, err) // Verify that we can successfully write data to the kafka broker err = k.Write(testutil.MockMetrics()) require.NoError(t, err) }
func TestConnectAndWrite(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } server := []string{testutil.GetLocalHost() + ":4150"} s, _ := serializers.NewInfluxSerializer() n := &NSQ{ Server: server[0], Topic: "telegraf", serializer: s, } // Verify that we can connect to the NSQ daemon err := n.Connect() require.NoError(t, err) // Verify that we can successfully write data to the NSQ daemon err = n.Write(testutil.MockMetrics()) require.NoError(t, err) }
func TestFileStdout(t *testing.T) { // keep backup of the real stdout old := os.Stdout r, w, _ := os.Pipe() os.Stdout = w s, _ := serializers.NewInfluxSerializer() f := File{ Files: []string{"stdout"}, serializer: s, } err := f.Connect() assert.NoError(t, err) err = f.Write(testutil.MockMetrics()) assert.NoError(t, err) err = f.Close() assert.NoError(t, err) outC := make(chan string) // copy the output in a separate goroutine so printing can't block indefinitely go func() { var buf bytes.Buffer io.Copy(&buf, r) outC <- buf.String() }() // back to normal state w.Close() // restoring the real stdout os.Stdout = old out := <-outC assert.Equal(t, expNewFile, out) }