From 56312cb07172e5630b7efb1bec29cb7560161cd4 Mon Sep 17 00:00:00 2001 From: Mohamed Osman Date: Thu, 22 Jun 2023 03:34:51 -0400 Subject: [PATCH] update unit tests --- .../gen/exporter/fileexporter/factory.go | 8 ++++---- .../fileexporter/file_exporter_test.go | 20 +++++++++---------- .../gen/receiver/otlpreceiver/otlp_test.go | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/collector/gen/exporter/fileexporter/factory.go b/collector/gen/exporter/fileexporter/factory.go index 62008e26..aec2a5b2 100644 --- a/collector/gen/exporter/fileexporter/factory.go +++ b/collector/gen/exporter/fileexporter/factory.go @@ -57,7 +57,7 @@ func createTracesExporter( if err != nil { return nil, err } - fe, err := exporters.GetOrAdd(cfg, func() (component.Component, error) { + fe, err := exporters.GetOrAdd(conf, func() (component.Component, error) { return newFileExporter(conf, writer), nil }) if err != nil { @@ -84,7 +84,7 @@ func createMetricsExporter( if err != nil { return nil, err } - fe, err := exporters.GetOrAdd(cfg, func() (component.Component, error) { + fe, err := exporters.GetOrAdd(conf, func() (component.Component, error) { return newFileExporter(conf, writer), nil }) if err != nil { @@ -111,7 +111,7 @@ func createLogsExporter( if err != nil { return nil, err } - fe, err := exporters.GetOrAdd(cfg, func() (component.Component, error) { + fe, err := exporters.GetOrAdd(conf, func() (component.Component, error) { return newFileExporter(conf, writer), nil }) if err != nil { @@ -172,4 +172,4 @@ func buildFileWriter(cfg *Config, logger *zap.Logger) (WriteCloseFlusher, error) // We maintain this map because the Factory is asked trace and metric receivers separately // when it gets CreateTracesReceiver() and CreateMetricsReceiver() but they must not // create separate objects, they must use one Receiver object per configuration. -var exporters = sharedcomponent.NewSharedComponents[component.Config, component.Component]() \ No newline at end of file +var exporters = sharedcomponent.NewSharedComponents[*Config, component.Component]() \ No newline at end of file diff --git a/collector/gen/exporter/fileexporter/file_exporter_test.go b/collector/gen/exporter/fileexporter/file_exporter_test.go index 692f9249..5bb9a96d 100644 --- a/collector/gen/exporter/fileexporter/file_exporter_test.go +++ b/collector/gen/exporter/fileexporter/file_exporter_test.go @@ -130,7 +130,7 @@ func TestFileTracesExporter(t *testing.T) { } require.NotNil(t, fe) - td := testdata.GenerateTracesTwoSpansSameResource() + td := testdata.GenerateTraces(2) assert.NoError(t, fe.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, fe.consumeTraces(context.Background(), td)) assert.NoError(t, fe.consumeTraces(context.Background(), td)) @@ -176,7 +176,7 @@ func TestFileTracesExporterError(t *testing.T) { } require.NotNil(t, fe) - td := testdata.GenerateTracesTwoSpansSameResource() + td := testdata.GenerateTraces(2) // Cannot call Start since we inject directly the WriterCloser. assert.Error(t, fe.consumeTraces(context.Background(), td)) assert.NoError(t, fe.Shutdown(context.Background())) @@ -267,7 +267,7 @@ func TestFileMetricsExporter(t *testing.T) { } require.NotNil(t, fe) - md := testdata.GenerateMetricsTwoMetrics() + md := testdata.GenerateMetrics(2) assert.NoError(t, fe.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, fe.consumeMetrics(context.Background(), md)) assert.NoError(t, fe.consumeMetrics(context.Background(), md)) @@ -314,7 +314,7 @@ func TestFileMetricsExporterError(t *testing.T) { } require.NotNil(t, fe) - md := testdata.GenerateMetricsTwoMetrics() + md := testdata.GenerateMetrics(2) // Cannot call Start since we inject directly the WriterCloser. assert.Error(t, fe.consumeMetrics(context.Background(), md)) assert.NoError(t, fe.Shutdown(context.Background())) @@ -405,7 +405,7 @@ func TestFileLogsExporter(t *testing.T) { } require.NotNil(t, fe) - ld := testdata.GenerateLogsTwoLogRecordsSameResource() + ld := testdata.GenerateLogs(2) assert.NoError(t, fe.Start(context.Background(), componenttest.NewNopHost())) assert.NoError(t, fe.consumeLogs(context.Background(), ld)) assert.NoError(t, fe.consumeLogs(context.Background(), ld)) @@ -452,7 +452,7 @@ func TestFileLogsExporterErrors(t *testing.T) { } require.NotNil(t, fe) - ld := testdata.GenerateLogsTwoLogRecordsSameResource() + ld := testdata.GenerateLogs(2) // Cannot call Start since we inject directly the WriterCloser. assert.Error(t, fe.consumeLogs(context.Background(), ld)) assert.NoError(t, fe.Shutdown(context.Background())) @@ -488,7 +488,7 @@ func TestExportMessageAsBuffer(t *testing.T) { } require.NotNil(t, fe) - ld := testdata.GenerateLogsManyLogRecordsSameResource(15000) + ld := testdata.GenerateLogs(15000) marshaler := &plog.ProtoMarshaler{} buf, err := marshaler.MarshalLogs(ld) assert.NoError(t, err) @@ -569,9 +569,9 @@ func TestConcurrentlyCompress(t *testing.T) { cmd []byte cld []byte ) - td := testdata.GenerateTracesTwoSpansSameResource() - md := testdata.GenerateMetricsTwoMetrics() - ld := testdata.GenerateLogsTwoLogRecordsSameResource() + td := testdata.GenerateTraces(2) + md := testdata.GenerateMetrics(2) + ld := testdata.GenerateLogs(2) go func() { defer wg.Done() buf, err := tracesMarshalers[formatTypeJSON].MarshalTraces(td) diff --git a/collector/gen/receiver/otlpreceiver/otlp_test.go b/collector/gen/receiver/otlpreceiver/otlp_test.go index 94a843e0..607ffc35 100644 --- a/collector/gen/receiver/otlpreceiver/otlp_test.go +++ b/collector/gen/receiver/otlpreceiver/otlp_test.go @@ -819,7 +819,7 @@ func TestGRPCInvalidTLSCredentials(t *testing.T) { assert.EqualError(t, r.Start(context.Background(), componenttest.NewNopHost()), - `failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither`) + `failed to load TLS config: failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither`) } func TestGRPCMaxRecvSize(t *testing.T) {