From 1151e9e0ef2eafeb86de6425701dfc5650c388d7 Mon Sep 17 00:00:00 2001 From: sakulali Date: Fri, 10 Nov 2023 23:11:21 +0800 Subject: [PATCH] [chore][receiver/windowseventlog] remove duplicate function NewFactory and pass checkapi (#29020) **Description:** Remove duplicate function NewFactory and pass checkapi. **Link to tracking Issue:** https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/26304 **Testing:** go run cmd/checkapi/main.go . go test for windowseventlogreceiver **Documentation:** Signed-off-by: sakulali --- cmd/checkapi/allowlist.txt | 1 - receiver/windowseventlogreceiver/factory.go | 13 +++++++++++++ .../windowseventlogreceiver/factory_test.go | 19 +++++++++++++++++++ .../receiver_others.go | 4 ++-- .../receiver_others_test.go | 2 +- .../receiver_windows.go | 4 ++-- .../receiver_windows_test.go | 14 +++++++------- 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 receiver/windowseventlogreceiver/factory.go create mode 100644 receiver/windowseventlogreceiver/factory_test.go diff --git a/cmd/checkapi/allowlist.txt b/cmd/checkapi/allowlist.txt index c784a1e659da..a7b4f0d35baf 100644 --- a/cmd/checkapi/allowlist.txt +++ b/cmd/checkapi/allowlist.txt @@ -4,4 +4,3 @@ extension/observer processor/servicegraphprocessor receiver/journaldreceiver receiver/kafkareceiver -receiver/windowseventlogreceiver diff --git a/receiver/windowseventlogreceiver/factory.go b/receiver/windowseventlogreceiver/factory.go new file mode 100644 index 000000000000..9d03534c2f40 --- /dev/null +++ b/receiver/windowseventlogreceiver/factory.go @@ -0,0 +1,13 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package windowseventlogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver" + +import ( + "go.opentelemetry.io/collector/receiver" +) + +// NewFactory creates a factory for windowseventlog receiver +func NewFactory() receiver.Factory { + return newFactoryAdapter() +} diff --git a/receiver/windowseventlogreceiver/factory_test.go b/receiver/windowseventlogreceiver/factory_test.go new file mode 100644 index 000000000000..a39ea31c1e4b --- /dev/null +++ b/receiver/windowseventlogreceiver/factory_test.go @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package windowseventlogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver" + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver/internal/metadata" +) + +func TestNewFactory(t *testing.T) { + t.Run("NewFactoryCorrectType", func(t *testing.T) { + factory := NewFactory() + require.EqualValues(t, metadata.Type, factory.Type()) + }) +} diff --git a/receiver/windowseventlogreceiver/receiver_others.go b/receiver/windowseventlogreceiver/receiver_others.go index 875682823ce9..e5eb1c6d041b 100644 --- a/receiver/windowseventlogreceiver/receiver_others.go +++ b/receiver/windowseventlogreceiver/receiver_others.go @@ -19,8 +19,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver/internal/metadata" ) -// NewFactory creates a factory for windowseventlog receiver -func NewFactory() receiver.Factory { +// newFactoryAdapter creates a dummy factory for windowseventlog receiver +func newFactoryAdapter() receiver.Factory { return receiver.NewFactory( metadata.Type, createDefaultConfig, diff --git a/receiver/windowseventlogreceiver/receiver_others_test.go b/receiver/windowseventlogreceiver/receiver_others_test.go index bd5850e848d6..000113d661f8 100644 --- a/receiver/windowseventlogreceiver/receiver_others_test.go +++ b/receiver/windowseventlogreceiver/receiver_others_test.go @@ -17,7 +17,7 @@ import ( ) func TestDefaultConfigFailure(t *testing.T) { - factory := NewFactory() + factory := newFactoryAdapter() cfg := factory.CreateDefaultConfig() require.NotNil(t, cfg, "failed to create default config") require.NoError(t, componenttest.CheckConfigStruct(cfg)) diff --git a/receiver/windowseventlogreceiver/receiver_windows.go b/receiver/windowseventlogreceiver/receiver_windows.go index dff763b5450d..e3e8d5e9742e 100644 --- a/receiver/windowseventlogreceiver/receiver_windows.go +++ b/receiver/windowseventlogreceiver/receiver_windows.go @@ -17,8 +17,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver/internal/metadata" ) -// NewFactory creates a factory for windowseventlog receiver -func NewFactory() receiver.Factory { +// newFactoryAdapter creates a factory for windowseventlog receiver +func newFactoryAdapter() receiver.Factory { return adapter.NewFactory(ReceiverType{}, metadata.LogsStability) } diff --git a/receiver/windowseventlogreceiver/receiver_windows_test.go b/receiver/windowseventlogreceiver/receiver_windows_test.go index 176954cd8091..7b7c7e289a29 100644 --- a/receiver/windowseventlogreceiver/receiver_windows_test.go +++ b/receiver/windowseventlogreceiver/receiver_windows_test.go @@ -30,7 +30,7 @@ import ( ) func TestDefaultConfig(t *testing.T) { - factory := NewFactory() + factory := newFactoryAdapter() cfg := factory.CreateDefaultConfig() require.NotNil(t, cfg, "failed to create default config") require.NoError(t, componenttest.CheckConfigStruct(cfg)) @@ -39,7 +39,7 @@ func TestDefaultConfig(t *testing.T) { func TestLoadConfig(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - factory := NewFactory() + factory := newFactoryAdapter() cfg := factory.CreateDefaultConfig() sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) @@ -60,7 +60,7 @@ func TestCreateWithInvalidInputConfig(t *testing.T) { }(), } - _, err := NewFactory().CreateLogsReceiver( + _, err := newFactoryAdapter().CreateLogsReceiver( context.Background(), receivertest.NewNopCreateSettings(), cfg, @@ -73,7 +73,7 @@ func TestReadWindowsEventLogger(t *testing.T) { logMessage := "Test log" ctx := context.Background() - factory := NewFactory() + factory := newFactoryAdapter() createSettings := receivertest.NewNopCreateSettings() cfg := createTestConfig() sink := new(consumertest.LogsSink) @@ -133,7 +133,7 @@ func TestReadWindowsEventLoggerRaw(t *testing.T) { logMessage := "Test log" ctx := context.Background() - factory := NewFactory() + factory := newFactoryAdapter() createSettings := receivertest.NewNopCreateSettings() cfg := createTestConfig() cfg.InputConfig.Raw = true @@ -186,7 +186,7 @@ func TestReadWindowsEventLoggerWithExcludeProvider(t *testing.T) { src := "otel" ctx := context.Background() - factory := NewFactory() + factory := newFactoryAdapter() createSettings := receivertest.NewNopCreateSettings() cfg := createTestConfig() cfg.InputConfig.ExcludeProviders = []string{src} @@ -225,7 +225,7 @@ func TestReadWindowsEventLoggerRawWithExcludeProvider(t *testing.T) { src := "otel" ctx := context.Background() - factory := NewFactory() + factory := newFactoryAdapter() createSettings := receivertest.NewNopCreateSettings() cfg := createTestConfig() cfg.InputConfig.Raw = true