factory_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package chronyreceiver
  4. import (
  5. "context"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/component/componenttest"
  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/chronyreceiver/internal/metadata"
  15. )
  16. func TestType(t *testing.T) {
  17. t.Parallel()
  18. factory := NewFactory()
  19. assert.Equal(t, component.Type("chrony"), factory.Type(), "Must match the expected type")
  20. }
  21. func TestValidConfig(t *testing.T) {
  22. t.Parallel()
  23. factory := NewFactory()
  24. assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig()))
  25. }
  26. func TestCreatingMetricsReceiver(t *testing.T) {
  27. t.Parallel()
  28. factory := NewFactory()
  29. mbc := metadata.DefaultMetricsBuilderConfig()
  30. mbc.Metrics = metadata.MetricsConfig{
  31. NtpTimeCorrection: metadata.MetricConfig{
  32. Enabled: true,
  33. },
  34. NtpSkew: metadata.MetricConfig{
  35. Enabled: true,
  36. },
  37. }
  38. mem, err := factory.CreateMetricsReceiver(
  39. context.Background(),
  40. receivertest.NewNopCreateSettings(),
  41. &Config{
  42. ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
  43. CollectionInterval: 30 * time.Second,
  44. Timeout: 10 * time.Second,
  45. },
  46. MetricsBuilderConfig: mbc,
  47. Endpoint: "udp://localhost:323",
  48. },
  49. consumertest.NewNop(),
  50. )
  51. assert.NoError(t, err, "Must not error creating metrics receiver")
  52. assert.NotNil(t, mem, "Must have a valid metrics receiver client")
  53. }