diff --git a/exporter/sumologicexporter/generated_component_test.go b/exporter/sumologicexporter/generated_component_test.go new file mode 100644 index 000000000000..fad215a00c06 --- /dev/null +++ b/exporter/sumologicexporter/generated_component_test.go @@ -0,0 +1,106 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package sumologicexporter + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" + + "go.opentelemetry.io/collector/exporter" + "go.opentelemetry.io/collector/exporter/exportertest" + + "go.opentelemetry.io/collector/confmap/confmaptest" + + "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata" +) + +// assertNoErrorHost implements a component.Host that asserts that there were no errors. +type assertNoErrorHost struct { + component.Host + *testing.T +} + +var _ component.Host = (*assertNoErrorHost)(nil) + +func TestComponentLifecycle(t *testing.T) { + factory := NewFactory() + + tests := []struct { + name string + createFn func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) + }{ + + { + name: "logs", + createFn: func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateLogsExporter(ctx, set, cfg) + }, + }, + + { + name: "metrics", + createFn: func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateMetricsExporter(ctx, set, cfg) + }, + }, + } + + 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(), exportertest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + err = c.Shutdown(context.Background()) + require.NoError(t, err) + }) + + t.Run(test.name+"-lifecycle", func(t *testing.T) { + + // TODO support lifecycle + t.SkipNow() + + c, err := test.createFn(context.Background(), exportertest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + host := componenttest.NewNopHost() + err = c.Start(context.Background(), host) + require.NoError(t, err) + require.NotPanics(t, func() { + switch e := c.(type) { + case exporter.Logs: + logs := testdata.GenerateLogsManyLogRecordsSameResource(2) + if !e.Capabilities().MutatesData { + logs.MarkReadOnly() + } + err = e.ConsumeLogs(context.Background(), logs) + case exporter.Metrics: + metrics := testdata.GenerateMetricsTwoMetrics() + if !e.Capabilities().MutatesData { + metrics.MarkReadOnly() + } + err = e.ConsumeMetrics(context.Background(), metrics) + case exporter.Traces: + traces := testdata.GenerateTracesTwoSpansSameResource() + if !e.Capabilities().MutatesData { + traces.MarkReadOnly() + } + err = e.ConsumeTraces(context.Background(), traces) + } + }) + + require.NoError(t, err) + + err = c.Shutdown(context.Background()) + require.NoError(t, err) + }) + } +} diff --git a/exporter/sumologicexporter/go.mod b/exporter/sumologicexporter/go.mod index d8b336071c21..96784118ca98 100644 --- a/exporter/sumologicexporter/go.mod +++ b/exporter/sumologicexporter/go.mod @@ -3,10 +3,12 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumolo go 1.20 require ( + github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.93.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.93.1-0.20240130182548-89388addcc7f go.opentelemetry.io/collector/config/confighttp v0.93.1-0.20240130182548-89388addcc7f go.opentelemetry.io/collector/config/configretry v0.93.1-0.20240130182548-89388addcc7f + go.opentelemetry.io/collector/confmap v0.93.1-0.20240130182548-89388addcc7f go.opentelemetry.io/collector/consumer v0.93.1-0.20240130182548-89388addcc7f go.opentelemetry.io/collector/exporter v0.93.1-0.20240130182548-89388addcc7f go.opentelemetry.io/collector/pdata v1.0.2-0.20240130181942-9c7177496fd5 @@ -50,10 +52,10 @@ require ( go.opentelemetry.io/collector/config/configtelemetry v0.93.1-0.20240130182548-89388addcc7f // indirect go.opentelemetry.io/collector/config/configtls v0.93.1-0.20240130182548-89388addcc7f // indirect go.opentelemetry.io/collector/config/internal v0.93.1-0.20240130182548-89388addcc7f // indirect - go.opentelemetry.io/collector/confmap v0.93.1-0.20240130182548-89388addcc7f // indirect go.opentelemetry.io/collector/extension v0.93.1-0.20240130182548-89388addcc7f // indirect go.opentelemetry.io/collector/extension/auth v0.93.1-0.20240130182548-89388addcc7f // indirect go.opentelemetry.io/collector/featuregate v1.0.2-0.20240130181942-9c7177496fd5 // indirect + go.opentelemetry.io/collector/receiver v0.93.1-0.20240130182548-89388addcc7f // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect go.opentelemetry.io/otel v1.22.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.45.0 // indirect @@ -75,3 +77,11 @@ retract ( v0.76.1 v0.65.0 ) + +replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden diff --git a/exporter/sumologicexporter/go.sum b/exporter/sumologicexporter/go.sum index 1613aade7598..7ddbb171eefc 100644 --- a/exporter/sumologicexporter/go.sum +++ b/exporter/sumologicexporter/go.sum @@ -106,7 +106,8 @@ go.opentelemetry.io/collector/featuregate v1.0.2-0.20240130181942-9c7177496fd5 h go.opentelemetry.io/collector/featuregate v1.0.2-0.20240130181942-9c7177496fd5/go.mod h1:QQXjP4etmJQhkQ20j4P/rapWuItYxoFozg/iIwuKnYg= go.opentelemetry.io/collector/pdata v1.0.2-0.20240130181942-9c7177496fd5 h1:cMc7sJ29OzK5jZqr6XFzKxiJvlypR/zt2TDhPDqpBic= go.opentelemetry.io/collector/pdata v1.0.2-0.20240130181942-9c7177496fd5/go.mod h1:IDkDj+B4Fp4wWOclBELN97zcb98HugJ8Q2gA4ZFsN8Q= -go.opentelemetry.io/collector/receiver v0.93.0 h1:oIMAqtG3b3tk+bokCK9T2kAmnFPtYKkph2hmtKcaDR8= +go.opentelemetry.io/collector/receiver v0.93.1-0.20240130182548-89388addcc7f h1:2C2QYMLF6YrRJPT/9LhRmfJ0wwF8nt4LjBblBCEJZtM= +go.opentelemetry.io/collector/receiver v0.93.1-0.20240130182548-89388addcc7f/go.mod h1:bPAxjHDsXFJZKPAturS7Ar5DDY/HJz5sj73E72vSVqk= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 h1:sv9kVfal0MK0wBMCOGr+HeJm9v803BkJxGrk2au7j08= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0/go.mod h1:SK2UL73Zy1quvRPonmOmRDiWk1KBV3LyIeeIxcEApWw= go.opentelemetry.io/otel v1.22.0 h1:xS7Ku+7yTFvDfDraDIJVpw7XPyuHlB9MCiqqX5mcJ6Y= diff --git a/exporter/sumologicexporter/metadata.yaml b/exporter/sumologicexporter/metadata.yaml index 7b7e746efafa..13c2c248ac91 100644 --- a/exporter/sumologicexporter/metadata.yaml +++ b/exporter/sumologicexporter/metadata.yaml @@ -7,3 +7,7 @@ status: distributions: [contrib] codeowners: active: [sumo-drosiek] + +tests: + config: + skip_lifecycle: true