Skip to content

Commit

Permalink
[chore] Remove usage of NopFactories when only one is needed (open-te…
Browse files Browse the repository at this point in the history
…lemetry#6663)

Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored and jaronoff97 committed Dec 14, 2022
1 parent 20727c6 commit 478b409
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
12 changes: 6 additions & 6 deletions service/internal/configunmarshaler/exporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import (
)

func TestExportersUnmarshal(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := component.MakeExporterFactoryMap(componenttest.NewNopExporterFactory())
require.NoError(t, err)

exps := NewExporters(factories.Exporters)
exps := NewExporters(factories)
conf := confmap.NewFromStringMap(map[string]interface{}{
"nop": nil,
"nop/myexporter": nil,
})
require.NoError(t, exps.Unmarshal(conf))

cfgWithName := factories.Exporters["nop"].CreateDefaultConfig()
cfgWithName := factories["nop"].CreateDefaultConfig()
cfgWithName.SetIDName("myexporter") //nolint:staticcheck
assert.Equal(t, map[component.ID]component.Config{
component.NewID("nop"): factories.Exporters["nop"].CreateDefaultConfig(),
component.NewID("nop"): factories["nop"].CreateDefaultConfig(),
component.NewIDWithName("nop", "myexporter"): cfgWithName,
}, exps.GetExporters())
}
Expand Down Expand Up @@ -100,12 +100,12 @@ func TestExportersUnmarshalError(t *testing.T) {
},
}

factories, err := componenttest.NopFactories()
factories, err := component.MakeExporterFactoryMap(componenttest.NewNopExporterFactory())
assert.NoError(t, err)

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
exps := NewExporters(factories.Exporters)
exps := NewExporters(factories)
err = exps.Unmarshal(tt.conf)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
Expand Down
15 changes: 8 additions & 7 deletions service/internal/configunmarshaler/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/extensiontest"
)

func TestExtensionsUnmarshal(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := extension.MakeFactoryMap(extensiontest.NewNopFactory())
require.NoError(t, err)

exts := NewExtensions(factories.Extensions)
exts := NewExtensions(factories)
conf := confmap.NewFromStringMap(map[string]interface{}{
"nop": nil,
"nop/myextension": nil,
})
require.NoError(t, exts.Unmarshal(conf))

cfgWithName := factories.Extensions["nop"].CreateDefaultConfig()
cfgWithName := factories["nop"].CreateDefaultConfig()
cfgWithName.SetIDName("myextension") //nolint:staticcheck
assert.Equal(t, map[component.ID]component.Config{
component.NewID("nop"): factories.Extensions["nop"].CreateDefaultConfig(),
component.NewID("nop"): factories["nop"].CreateDefaultConfig(),
component.NewIDWithName("nop", "myextension"): cfgWithName,
}, exts.GetExtensions())
}
Expand Down Expand Up @@ -100,12 +101,12 @@ func TestExtensionsUnmarshalError(t *testing.T) {
},
}

factories, err := componenttest.NopFactories()
factories, err := extension.MakeFactoryMap(extensiontest.NewNopFactory())
assert.NoError(t, err)

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
exts := NewExtensions(factories.Extensions)
exts := NewExtensions(factories)
err = exts.Unmarshal(tt.conf)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
Expand Down
12 changes: 6 additions & 6 deletions service/internal/configunmarshaler/processors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import (
)

func TestProcessorsUnmarshal(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := component.MakeProcessorFactoryMap(componenttest.NewNopProcessorFactory())
require.NoError(t, err)

procs := NewProcessors(factories.Processors)
procs := NewProcessors(factories)
conf := confmap.NewFromStringMap(map[string]interface{}{
"nop": nil,
"nop/myprocessor": nil,
})
require.NoError(t, procs.Unmarshal(conf))

cfgWithName := factories.Processors["nop"].CreateDefaultConfig()
cfgWithName := factories["nop"].CreateDefaultConfig()
cfgWithName.SetIDName("myprocessor") //nolint:staticcheck
assert.Equal(t, map[component.ID]component.Config{
component.NewID("nop"): factories.Processors["nop"].CreateDefaultConfig(),
component.NewID("nop"): factories["nop"].CreateDefaultConfig(),
component.NewIDWithName("nop", "myprocessor"): cfgWithName,
}, procs.procs)
}
Expand Down Expand Up @@ -100,12 +100,12 @@ func TestProcessorsUnmarshalError(t *testing.T) {
},
}

factories, err := componenttest.NopFactories()
factories, err := component.MakeProcessorFactoryMap(componenttest.NewNopProcessorFactory())
assert.NoError(t, err)

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
procs := NewProcessors(factories.Processors)
procs := NewProcessors(factories)
err = procs.Unmarshal(tt.conf)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
Expand Down
12 changes: 6 additions & 6 deletions service/internal/configunmarshaler/receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import (
)

func TestReceiversUnmarshal(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := component.MakeReceiverFactoryMap(componenttest.NewNopReceiverFactory())
require.NoError(t, err)

recvs := NewReceivers(factories.Receivers)
recvs := NewReceivers(factories)
conf := confmap.NewFromStringMap(map[string]interface{}{
"nop": nil,
"nop/myreceiver": nil,
})
require.NoError(t, recvs.Unmarshal(conf))

cfgWithName := factories.Receivers["nop"].CreateDefaultConfig()
cfgWithName := factories["nop"].CreateDefaultConfig()
cfgWithName.SetIDName("myreceiver") //nolint:staticcheck
assert.Equal(t, map[component.ID]component.Config{
component.NewID("nop"): factories.Receivers["nop"].CreateDefaultConfig(),
component.NewID("nop"): factories["nop"].CreateDefaultConfig(),
component.NewIDWithName("nop", "myreceiver"): cfgWithName,
}, recvs.GetReceivers())
}
Expand Down Expand Up @@ -100,12 +100,12 @@ func TestReceiversUnmarshalError(t *testing.T) {
},
}

factories, err := componenttest.NopFactories()
factories, err := component.MakeReceiverFactoryMap(componenttest.NewNopReceiverFactory())
assert.NoError(t, err)

for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
recvs := NewReceivers(factories.Receivers)
recvs := NewReceivers(factories)
err = recvs.Unmarshal(tt.conf)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
Expand Down

0 comments on commit 478b409

Please sign in to comment.