123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package splunkenterprisereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkenterprisereceiver"
- import (
- "context"
- "testing"
- "time"
- "github.com/stretchr/testify/require"
- "go.opentelemetry.io/collector/config/confighttp"
- "go.opentelemetry.io/collector/config/configopaque"
- "go.opentelemetry.io/collector/consumer/consumertest"
- "go.opentelemetry.io/collector/receiver/receivertest"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkenterprisereceiver/internal/metadata"
- )
- func TestFactoryCreate(t *testing.T) {
- factory := NewFactory()
- require.EqualValues(t, "splunkenterprise", factory.Type())
- }
- func TestDefaultConfig(t *testing.T) {
- cfg := confighttp.NewDefaultHTTPClientSettings()
- cfg.Headers = map[string]configopaque.String{
- "Content-Type": "application/x-www-form-urlencoded",
- }
- expectedConf := &Config{
- HTTPClientSettings: cfg,
- ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
- CollectionInterval: 10 * time.Minute,
- InitialDelay: 1 * time.Second,
- Timeout: 60 * time.Second,
- },
- MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
- }
- testConf := createDefaultConfig().(*Config)
- require.Equal(t, expectedConf, testConf)
- }
- func TestCreateMetricsReceiver(t *testing.T) {
- tests := []struct {
- desc string
- run func(t *testing.T)
- }{
- {
- desc: "Defaults with valid config",
- run: func(t *testing.T) {
- t.Parallel()
- cfg := createDefaultConfig().(*Config)
- _, err := createMetricsReceiver(
- context.Background(),
- receivertest.NewNopCreateSettings(),
- cfg,
- consumertest.NewNop(),
- )
- require.NoError(t, err, "failed to create metrics receiver with valid inputs")
- },
- },
- {
- desc: "Missing consumer",
- run: func(t *testing.T) {
- t.Parallel()
- cfg := createDefaultConfig().(*Config)
- _, err := createMetricsReceiver(
- context.Background(),
- receivertest.NewNopCreateSettings(),
- cfg,
- nil,
- )
- require.Error(t, err, "created metrics receiver without consumer")
- },
- },
- }
- for _, test := range tests {
- t.Run(test.desc, test.run)
- }
- }
|