config_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package redisreceiver
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. "go.opentelemetry.io/collector/component"
  11. "go.opentelemetry.io/collector/config/confignet"
  12. "go.opentelemetry.io/collector/config/configtls"
  13. "go.opentelemetry.io/collector/confmap/confmaptest"
  14. "go.opentelemetry.io/collector/receiver/scraperhelper"
  15. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver/internal/metadata"
  16. )
  17. func TestConfig(t *testing.T) {
  18. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  19. require.NoError(t, err)
  20. factory := NewFactory()
  21. cfg := factory.CreateDefaultConfig()
  22. sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
  23. require.NoError(t, err)
  24. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  25. assert.Equal(t,
  26. &Config{
  27. NetAddr: confignet.NetAddr{
  28. Endpoint: "localhost:6379",
  29. Transport: "tcp",
  30. },
  31. TLS: configtls.TLSClientSetting{
  32. Insecure: true,
  33. },
  34. Username: "test",
  35. Password: "test",
  36. ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
  37. CollectionInterval: 10 * time.Second,
  38. InitialDelay: time.Second,
  39. },
  40. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  41. },
  42. cfg,
  43. )
  44. }