factory_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package bigipreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/bigipreceiver"
  4. import (
  5. "context"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/config/confighttp"
  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/bigipreceiver/internal/metadata"
  15. )
  16. func TestNewFactory(t *testing.T) {
  17. testCases := []struct {
  18. desc string
  19. testFunc func(*testing.T)
  20. }{
  21. {
  22. desc: "creates a new factory with correct type",
  23. testFunc: func(t *testing.T) {
  24. factory := NewFactory()
  25. require.EqualValues(t, metadata.Type, factory.Type())
  26. },
  27. },
  28. {
  29. desc: "creates a new factory with valid default config",
  30. testFunc: func(t *testing.T) {
  31. factory := NewFactory()
  32. var expectedCfg component.Config = &Config{
  33. ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
  34. CollectionInterval: 10 * time.Second,
  35. },
  36. HTTPClientSettings: confighttp.HTTPClientSettings{
  37. Endpoint: defaultEndpoint,
  38. Timeout: 10 * time.Second,
  39. },
  40. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  41. }
  42. require.Equal(t, expectedCfg, factory.CreateDefaultConfig())
  43. },
  44. },
  45. {
  46. desc: "creates a new factory and CreateMetricsReceiver returns no error",
  47. testFunc: func(t *testing.T) {
  48. factory := NewFactory()
  49. cfg := factory.CreateDefaultConfig()
  50. _, err := factory.CreateMetricsReceiver(
  51. context.Background(),
  52. receivertest.NewNopCreateSettings(),
  53. cfg,
  54. consumertest.NewNop(),
  55. )
  56. require.NoError(t, err)
  57. },
  58. },
  59. {
  60. desc: "creates a new factory and CreateMetricsReceiver returns error with incorrect config",
  61. testFunc: func(t *testing.T) {
  62. factory := NewFactory()
  63. _, err := factory.CreateMetricsReceiver(
  64. context.Background(),
  65. receivertest.NewNopCreateSettings(),
  66. nil,
  67. consumertest.NewNop(),
  68. )
  69. require.ErrorIs(t, err, errConfigNotBigip)
  70. },
  71. },
  72. }
  73. for _, tc := range testCases {
  74. t.Run(tc.desc, tc.testFunc)
  75. }
  76. }