factory_test.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package riakreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/riakreceiver"
  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/riakreceiver/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. InitialDelay: time.Second,
  36. },
  37. HTTPClientSettings: confighttp.HTTPClientSettings{
  38. Endpoint: defaultEndpoint,
  39. Timeout: 10 * time.Second,
  40. },
  41. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  42. }
  43. require.Equal(t, expectedCfg, factory.CreateDefaultConfig())
  44. },
  45. },
  46. {
  47. desc: "creates a new factory and CreateMetricsReceiver returns no error",
  48. testFunc: func(t *testing.T) {
  49. factory := NewFactory()
  50. cfg := factory.CreateDefaultConfig()
  51. _, err := factory.CreateMetricsReceiver(
  52. context.Background(),
  53. receivertest.NewNopCreateSettings(),
  54. cfg,
  55. consumertest.NewNop(),
  56. )
  57. require.NoError(t, err)
  58. },
  59. },
  60. {
  61. desc: "creates a new factory and CreateMetricsReceiver returns error with incorrect config",
  62. testFunc: func(t *testing.T) {
  63. factory := NewFactory()
  64. _, err := factory.CreateMetricsReceiver(
  65. context.Background(),
  66. receivertest.NewNopCreateSettings(),
  67. nil,
  68. consumertest.NewNop(),
  69. )
  70. require.ErrorIs(t, err, errConfigNotRiak)
  71. },
  72. },
  73. }
  74. for _, tc := range testCases {
  75. t.Run(tc.desc, tc.testFunc)
  76. }
  77. }