From 24cfa93ba3dc56e170a2212fc608b1974635e9b5 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Sat, 3 Feb 2024 05:23:43 +0800 Subject: [PATCH] [chore] move azuredataexpoter exporter to generated lifecycle tests (#30514) Relates to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27849 --------- Co-authored-by: Antoine Toulme --- .../generated_component_test.go | 113 ++++++++++++++++++ .../azuredataexplorerexporter/metadata.yaml | 10 +- 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 exporter/azuredataexplorerexporter/generated_component_test.go diff --git a/exporter/azuredataexplorerexporter/generated_component_test.go b/exporter/azuredataexplorerexporter/generated_component_test.go new file mode 100644 index 000000000000..ad0fdf341179 --- /dev/null +++ b/exporter/azuredataexplorerexporter/generated_component_test.go @@ -0,0 +1,113 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package azuredataexplorerexporter + +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) + }, + }, + + { + name: "traces", + createFn: func(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateTracesExporter(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/azuredataexplorerexporter/metadata.yaml b/exporter/azuredataexplorerexporter/metadata.yaml index 7b7c031da4da..942b3c6ffae6 100644 --- a/exporter/azuredataexplorerexporter/metadata.yaml +++ b/exporter/azuredataexplorerexporter/metadata.yaml @@ -6,4 +6,12 @@ status: beta: [traces, metrics, logs] distributions: [contrib] codeowners: - active: [asaharn, ag-ramachandran] \ No newline at end of file + active: [asaharn, ag-ramachandran] + +tests: + config: + cluster_uri: "https://CLUSTER.kusto.windows.net" + application_id: "f80da32c-108c-415c-a19e-643f461a677a" + application_key: "xx-xx-xx-xx" + tenant_id: "21ff9e36-fbaa-43c8-98ba-00431ea10bc3" + skip_lifecycle: true \ No newline at end of file