diff --git a/connector/datadogconnector/generated_component_test.go b/connector/datadogconnector/generated_component_test.go new file mode 100644 index 000000000000..105efdb4c774 --- /dev/null +++ b/connector/datadogconnector/generated_component_test.go @@ -0,0 +1,93 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package datadogconnector + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" + + "go.opentelemetry.io/collector/connector" + "go.opentelemetry.io/collector/connector/connectortest" + "go.opentelemetry.io/collector/consumer/consumertest" + + "go.opentelemetry.io/collector/confmap/confmaptest" +) + +// assertNoErrorHost implements a component.Host that asserts that there were no errors. +type assertNoErrorHost struct { + component.Host + *testing.T +} + +var _ component.Host = (*assertNoErrorHost)(nil) + +// newAssertNoErrorHost returns a new instance of assertNoErrorHost. +func newAssertNoErrorHost(t *testing.T) component.Host { + return &assertNoErrorHost{ + componenttest.NewNopHost(), + t, + } +} + +func (aneh *assertNoErrorHost) ReportFatalError(err error) { + assert.NoError(aneh, err) +} + +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) { + return factory.CreateTracesToMetrics(ctx, set, cfg, consumertest.NewNop()) + }, + }, + + { + name: "traces_to_traces", + createFn: func(ctx context.Context, set connector.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateTracesToTraces(ctx, set, cfg, consumertest.NewNop()) + }, + }, + } + + 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, component.UnmarshalConfig(sub, 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 := newAssertNoErrorHost(t) + 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())) + }) + } +} diff --git a/connector/datadogconnector/go.mod b/connector/datadogconnector/go.mod index 9713c573c70c..a045ccdd59cd 100644 --- a/connector/datadogconnector/go.mod +++ b/connector/datadogconnector/go.mod @@ -12,6 +12,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.95.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.95.0 + go.opentelemetry.io/collector/confmap v0.95.0 go.opentelemetry.io/collector/connector v0.95.0 go.opentelemetry.io/collector/consumer v0.95.0 go.opentelemetry.io/collector/exporter v0.95.0 @@ -149,7 +150,6 @@ require ( go.opentelemetry.io/collector/config/configtelemetry v0.95.0 // indirect go.opentelemetry.io/collector/config/configtls v0.95.0 // indirect go.opentelemetry.io/collector/config/internal v0.95.0 // indirect - go.opentelemetry.io/collector/confmap v0.95.0 // indirect go.opentelemetry.io/collector/confmap/converter/expandconverter v0.95.0 // indirect go.opentelemetry.io/collector/confmap/provider/envprovider v0.95.0 // indirect go.opentelemetry.io/collector/confmap/provider/fileprovider v0.95.0 // indirect diff --git a/connector/datadogconnector/metadata.yaml b/connector/datadogconnector/metadata.yaml index 907ef0b3c104..66bac9e10f8b 100644 --- a/connector/datadogconnector/metadata.yaml +++ b/connector/datadogconnector/metadata.yaml @@ -8,3 +8,6 @@ status: codeowners: active: [mx-psi, dineshg13] emeritus: [gbbr] + +tests: + config: