factory_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package vcenterreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/vcenterreceiver"
  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 TestCreateMetricsReceiver(t *testing.T) {
  13. testCases := []struct {
  14. desc string
  15. testFn func(t *testing.T)
  16. }{
  17. {
  18. desc: "Default config",
  19. testFn: func(t *testing.T) {
  20. t.Parallel()
  21. _, err := createMetricsReceiver(
  22. context.Background(),
  23. receivertest.NewNopCreateSettings(),
  24. createDefaultConfig(),
  25. consumertest.NewNop(),
  26. )
  27. require.NoError(t, err)
  28. },
  29. },
  30. {
  31. desc: "Nil config",
  32. testFn: func(t *testing.T) {
  33. t.Parallel()
  34. _, err := createMetricsReceiver(
  35. context.Background(),
  36. receivertest.NewNopCreateSettings(),
  37. nil,
  38. consumertest.NewNop(),
  39. )
  40. require.ErrorIs(t, err, errConfigNotVcenter)
  41. },
  42. },
  43. {
  44. desc: "Nil consumer",
  45. testFn: 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.testFn)
  59. }
  60. }