// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package riakreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/riakreceiver" import ( "context" "testing" "time" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" "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/riakreceiver/internal/metadata" ) func TestNewFactory(t *testing.T) { testCases := []struct { desc string testFunc func(*testing.T) }{ { desc: "creates a new factory with correct type", testFunc: func(t *testing.T) { factory := NewFactory() require.EqualValues(t, metadata.Type, factory.Type()) }, }, { desc: "creates a new factory with valid default config", testFunc: func(t *testing.T) { factory := NewFactory() var expectedCfg component.Config = &Config{ ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ CollectionInterval: 10 * time.Second, InitialDelay: time.Second, }, HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: defaultEndpoint, Timeout: 10 * time.Second, }, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } require.Equal(t, expectedCfg, factory.CreateDefaultConfig()) }, }, { desc: "creates a new factory and CreateMetricsReceiver returns no error", testFunc: func(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() _, err := factory.CreateMetricsReceiver( context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop(), ) require.NoError(t, err) }, }, { desc: "creates a new factory and CreateMetricsReceiver returns error with incorrect config", testFunc: func(t *testing.T) { factory := NewFactory() _, err := factory.CreateMetricsReceiver( context.Background(), receivertest.NewNopCreateSettings(), nil, consumertest.NewNop(), ) require.ErrorIs(t, err, errConfigNotRiak) }, }, } for _, tc := range testCases { t.Run(tc.desc, tc.testFunc) } }