factory_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package couchdbreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/couchdbreceiver"
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/require"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/consumer/consumertest"
  10. "go.opentelemetry.io/collector/receiver/receivertest"
  11. )
  12. func TestType(t *testing.T) {
  13. factory := NewFactory()
  14. ft := factory.Type()
  15. require.EqualValues(t, "couchdb", ft)
  16. }
  17. func TestValidConfig(t *testing.T) {
  18. factory := NewFactory()
  19. cfg := factory.CreateDefaultConfig().(*Config)
  20. cfg.Username = "otel"
  21. cfg.Password = "otel"
  22. require.EqualValues(t, defaultEndpoint, cfg.Endpoint)
  23. require.NoError(t, component.ValidateConfig(cfg))
  24. }
  25. func TestCreateMetricsReceiver(t *testing.T) {
  26. testCases := []struct {
  27. desc string
  28. run func(t *testing.T)
  29. }{
  30. {
  31. desc: "Default config",
  32. run: func(t *testing.T) {
  33. t.Parallel()
  34. _, err := createMetricsReceiver(
  35. context.Background(),
  36. receivertest.NewNopCreateSettings(),
  37. createDefaultConfig(),
  38. consumertest.NewNop(),
  39. )
  40. require.NoError(t, err)
  41. },
  42. },
  43. {
  44. desc: "Nil consumer",
  45. run: func(t *testing.T) {
  46. t.Parallel()
  47. _, err := createMetricsReceiver(
  48. context.Background(),
  49. receivertest.NewNopCreateSettings(),
  50. createDefaultConfig(),
  51. nil,
  52. )
  53. require.ErrorIs(t, err, component.ErrNilNextConsumer)
  54. },
  55. },
  56. }
  57. for _, testCase := range testCases {
  58. t.Run(testCase.desc, testCase.run)
  59. }
  60. }