forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporter_test.go
81 lines (73 loc) · 2.19 KB
/
exporter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package awskinesisexporter
import (
"context"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
"github.com/stretchr/testify/assert"
"go.uber.org/zap/zaptest"
)
func MustTestGeneric[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}
func applyConfigChanges(fn func(conf *Config)) *Config {
conf := createDefaultConfig().(*Config)
fn(conf)
return conf
}
func TestCreatingExporter(t *testing.T) {
t.Parallel()
for _, tc := range []struct {
name string
conf *Config
validateNew func(tb testing.TB) func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client
err error
}{
{
name: "Default configuration",
conf: applyConfigChanges(func(conf *Config) {
conf.AWS.StreamName = "example-test"
}),
validateNew: func(tb testing.TB) func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
return func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
assert.Equal(tb, conf.Region, "us-west-2", "Must match the expected region")
k := kinesis.NewFromConfig(conf, opts...)
return k
}
},
},
{
name: "Apply different region",
conf: applyConfigChanges(func(conf *Config) {
conf.AWS.StreamName = "example-test"
conf.AWS.Region = "us-east-1"
}),
validateNew: func(tb testing.TB) func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
return func(conf aws.Config, opts ...func(*kinesis.Options)) *kinesis.Client {
assert.Equal(tb, conf.Region, "us-east-1", "Must match the expected region")
k := kinesis.NewFromConfig(conf, opts...)
return k
}
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
exp, err := createExporter(context.Background(), tc.conf, zaptest.NewLogger(t), func(opt *options) {
opt.NewKinesisClient = tc.validateNew(t)
})
assert.ErrorIs(t, err, tc.err, "Must match the expected error")
if tc.err != nil {
assert.Nil(t, exp, "Must be nil if error returned")
return
}
assert.NotNil(t, exp, "Must not be nil if no error is returned")
})
}
}