2015-12-10 02:07:55 +00:00
|
|
|
package kinesis_output
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-12-10 09:54:30 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/ec2metadata"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
|
|
"github.com/aws/aws-sdk-go/service/kinesis"
|
2015-12-11 00:45:35 +00:00
|
|
|
"github.com/influxdb/telegraf/testutil"
|
2015-12-10 02:07:55 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConnectAndWrite(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
|
|
|
|
2015-12-11 00:45:35 +00:00
|
|
|
k := &KinesisOutput{
|
|
|
|
Region: "us-west-2",
|
|
|
|
}
|
|
|
|
|
2015-12-10 02:07:55 +00:00
|
|
|
// Verify that we can connect kinesis endpoint. This test allows for a chain of credential
|
|
|
|
// so that various authentication methods can pass depending on the system that executes.
|
|
|
|
Config := &aws.Config{
|
2015-12-11 00:45:35 +00:00
|
|
|
Region: aws.String(k.Region),
|
2015-12-10 02:07:55 +00:00
|
|
|
Credentials: credentials.NewChainCredentials(
|
|
|
|
[]credentials.Provider{
|
|
|
|
&ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())},
|
|
|
|
&credentials.EnvProvider{},
|
|
|
|
&credentials.SharedCredentialsProvider{},
|
|
|
|
}),
|
|
|
|
}
|
2015-12-10 09:54:30 +00:00
|
|
|
svc := kinesis.New(session.New(Config))
|
|
|
|
|
|
|
|
KinesisParams := &kinesis.ListStreamsInput{
|
|
|
|
Limit: aws.Int64(1)}
|
2015-12-11 00:45:35 +00:00
|
|
|
_, err := svc.ListStreams(KinesisParams)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Unable to connect to Kinesis")
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFormatMetric(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
2015-12-10 09:54:30 +00:00
|
|
|
|
2015-12-11 00:45:35 +00:00
|
|
|
k := &KinesisOutput{
|
|
|
|
Format: "string",
|
|
|
|
}
|
|
|
|
|
|
|
|
p := testutil.MockBatchPoints().Points()[0]
|
|
|
|
|
|
|
|
valid_string := "test1,tag1=value1 value=1 1257894000000000000"
|
|
|
|
func_string, err := FormatMetric(k, p)
|
|
|
|
|
|
|
|
if func_string != valid_string {
|
|
|
|
t.Error("Expected ", valid_string)
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
k = &KinesisOutput{
|
|
|
|
Format: "custom",
|
|
|
|
}
|
2015-12-10 02:07:55 +00:00
|
|
|
|
2015-12-11 00:45:35 +00:00
|
|
|
valid_custom := "test1,map[tag1:value1],test1,tag1=value1 value=1 1257894000000000000"
|
|
|
|
func_custom, err := FormatMetric(k, p)
|
|
|
|
|
|
|
|
if func_custom != valid_custom {
|
|
|
|
t.Error("Expected ", valid_custom)
|
|
|
|
}
|
2015-12-10 02:07:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|