factory_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package splunkenterprisereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkenterprisereceiver"
  4. import (
  5. "context"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/config/confighttp"
  10. "go.opentelemetry.io/collector/config/configopaque"
  11. "go.opentelemetry.io/collector/consumer/consumertest"
  12. "go.opentelemetry.io/collector/receiver/receivertest"
  13. "go.opentelemetry.io/collector/receiver/scraperhelper"
  14. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkenterprisereceiver/internal/metadata"
  15. )
  16. func TestFactoryCreate(t *testing.T) {
  17. factory := NewFactory()
  18. require.EqualValues(t, "splunkenterprise", factory.Type())
  19. }
  20. func TestDefaultConfig(t *testing.T) {
  21. cfg := confighttp.NewDefaultHTTPClientSettings()
  22. cfg.Headers = map[string]configopaque.String{
  23. "Content-Type": "application/x-www-form-urlencoded",
  24. }
  25. expectedConf := &Config{
  26. HTTPClientSettings: cfg,
  27. ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
  28. CollectionInterval: 10 * time.Minute,
  29. InitialDelay: 1 * time.Second,
  30. Timeout: 60 * time.Second,
  31. },
  32. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  33. }
  34. testConf := createDefaultConfig().(*Config)
  35. require.Equal(t, expectedConf, testConf)
  36. }
  37. func TestCreateMetricsReceiver(t *testing.T) {
  38. tests := []struct {
  39. desc string
  40. run func(t *testing.T)
  41. }{
  42. {
  43. desc: "Defaults with valid config",
  44. run: func(t *testing.T) {
  45. t.Parallel()
  46. cfg := createDefaultConfig().(*Config)
  47. _, err := createMetricsReceiver(
  48. context.Background(),
  49. receivertest.NewNopCreateSettings(),
  50. cfg,
  51. consumertest.NewNop(),
  52. )
  53. require.NoError(t, err, "failed to create metrics receiver with valid inputs")
  54. },
  55. },
  56. {
  57. desc: "Missing consumer",
  58. run: func(t *testing.T) {
  59. t.Parallel()
  60. cfg := createDefaultConfig().(*Config)
  61. _, err := createMetricsReceiver(
  62. context.Background(),
  63. receivertest.NewNopCreateSettings(),
  64. cfg,
  65. nil,
  66. )
  67. require.Error(t, err, "created metrics receiver without consumer")
  68. },
  69. },
  70. }
  71. for _, test := range tests {
  72. t.Run(test.desc, test.run)
  73. }
  74. }