Skip to content

Commit

Permalink
[chore][receiver/windowseventlog] remove duplicate function NewFactor…
Browse files Browse the repository at this point in the history
…y and pass checkapi (open-telemetry#29020)

**Description:**
Remove duplicate function NewFactory and pass checkapi.

**Link to tracking Issue:**

open-telemetry#26304

**Testing:**
go run cmd/checkapi/main.go .
go test for windowseventlogreceiver

**Documentation:**

Signed-off-by: sakulali <sakulali@126.com>
  • Loading branch information
sakulali authored and RoryCrispin committed Nov 24, 2023
1 parent 3c314ed commit 1151e9e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
1 change: 0 additions & 1 deletion cmd/checkapi/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ extension/observer
processor/servicegraphprocessor
receiver/journaldreceiver
receiver/kafkareceiver
receiver/windowseventlogreceiver
13 changes: 13 additions & 0 deletions receiver/windowseventlogreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -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()
}
19 changes: 19 additions & 0 deletions receiver/windowseventlogreceiver/factory_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
}
4 changes: 2 additions & 2 deletions receiver/windowseventlogreceiver/receiver_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion receiver/windowseventlogreceiver/receiver_others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions receiver/windowseventlogreceiver/receiver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
14 changes: 7 additions & 7 deletions receiver/windowseventlogreceiver/receiver_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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())
Expand All @@ -60,7 +60,7 @@ func TestCreateWithInvalidInputConfig(t *testing.T) {
}(),
}

_, err := NewFactory().CreateLogsReceiver(
_, err := newFactoryAdapter().CreateLogsReceiver(
context.Background(),
receivertest.NewNopCreateSettings(),
cfg,
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1151e9e

Please sign in to comment.