-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for config, factory, and reciever
- Loading branch information
Showing
6 changed files
with
400 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package libhoneyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver" | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
) | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
assert.NotNil(t, cfg, "failed to create default config") | ||
assert.NoError(t, componenttest.CheckConfigStruct(cfg)) | ||
|
||
libhoneyCfg, ok := cfg.(*Config) | ||
require.True(t, ok, "invalid Config type") | ||
|
||
assert.Equal(t, "localhost:8080", libhoneyCfg.HTTP.Endpoint) | ||
assert.Equal(t, []string{"/events", "/event", "/batch"}, libhoneyCfg.HTTP.TracesURLPaths) | ||
assert.Equal(t, "", libhoneyCfg.AuthAPI) | ||
assert.Equal(t, "service.name", libhoneyCfg.FieldMapConfig.Resources.ServiceName) | ||
assert.Equal(t, "library.name", libhoneyCfg.FieldMapConfig.Scopes.LibraryName) | ||
assert.Equal(t, []string{"duration_ms"}, libhoneyCfg.FieldMapConfig.Attributes.DurationFields) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package libhoneyreceiver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/receiver/receivertest" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver/internal/metadata" | ||
) | ||
|
||
func TestCreateTracesReceiver(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
set := receivertest.NewNopSettings() | ||
tReceiver, err := factory.CreateTraces(context.Background(), set, cfg, consumertest.NewNop()) | ||
|
||
assert.NoError(t, err, "receiver creation failed") | ||
assert.NotNil(t, tReceiver, "receiver creation failed") | ||
|
||
assert.NoError(t, tReceiver.Start(context.Background(), componenttest.NewNopHost())) | ||
assert.NoError(t, tReceiver.Shutdown(context.Background())) | ||
} | ||
|
||
func TestCreateLogsReceiver(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
set := receivertest.NewNopSettings() | ||
lReceiver, err := factory.CreateLogs(context.Background(), set, cfg, consumertest.NewNop()) | ||
|
||
assert.NoError(t, err, "receiver creation failed") | ||
assert.NotNil(t, lReceiver, "receiver creation failed") | ||
|
||
assert.NoError(t, lReceiver.Start(context.Background(), componenttest.NewNopHost())) | ||
assert.NoError(t, lReceiver.Shutdown(context.Background())) | ||
} | ||
|
||
func TestType(t *testing.T) { | ||
factory := NewFactory() | ||
assert.Equal(t, metadata.Type, factory.Type()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.