forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generated_component_test.go
71 lines (61 loc) · 2.47 KB
/
generated_component_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
// Code generated by mdatagen. DO NOT EDIT.
package spanmetricsconnector
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/connector/connectortest"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumertest"
)
func TestComponentFactoryType(t *testing.T) {
require.Equal(t, "spanmetrics", NewFactory().Type().String())
}
func TestComponentConfigStruct(t *testing.T) {
require.NoError(t, componenttest.CheckConfigStruct(NewFactory().CreateDefaultConfig()))
}
func TestComponentLifecycle(t *testing.T) {
factory := NewFactory()
tests := []struct {
name string
createFn func(ctx context.Context, set connector.CreateSettings, cfg component.Config) (component.Component, error)
}{
{
name: "traces_to_metrics",
createFn: func(ctx context.Context, set connector.CreateSettings, cfg component.Config) (component.Component, error) {
router := connector.NewMetricsRouter(map[component.ID]consumer.Metrics{component.NewID(component.DataTypeMetrics): consumertest.NewNop()})
return factory.CreateTracesToMetrics(ctx, set, cfg, router)
},
},
}
cm, err := confmaptest.LoadConf("metadata.yaml")
require.NoError(t, err)
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub("tests::config")
require.NoError(t, err)
require.NoError(t, sub.Unmarshal(&cfg))
for _, test := range tests {
t.Run(test.name+"-shutdown", func(t *testing.T) {
c, err := test.createFn(context.Background(), connectortest.NewNopCreateSettings(), cfg)
require.NoError(t, err)
err = c.Shutdown(context.Background())
require.NoError(t, err)
})
t.Run(test.name+"-lifecycle", func(t *testing.T) {
firstConnector, err := test.createFn(context.Background(), connectortest.NewNopCreateSettings(), cfg)
require.NoError(t, err)
host := componenttest.NewNopHost()
require.NoError(t, err)
require.NoError(t, firstConnector.Start(context.Background(), host))
require.NoError(t, firstConnector.Shutdown(context.Background()))
secondConnector, err := test.createFn(context.Background(), connectortest.NewNopCreateSettings(), cfg)
require.NoError(t, err)
require.NoError(t, secondConnector.Start(context.Background(), host))
require.NoError(t, secondConnector.Shutdown(context.Background()))
})
}
}