config_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"
  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/confmap/confmaptest"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver/internal/metadata"
  13. )
  14. func TestLoadConfig(t *testing.T) {
  15. t.Parallel()
  16. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  17. require.NoError(t, err)
  18. tests := []struct {
  19. id component.ID
  20. expected component.Config
  21. }{
  22. {
  23. id: component.NewID(metadata.Type),
  24. expected: &Config{
  25. ArrayName: "foobar.example.com",
  26. Settings: &Settings{
  27. ReloadIntervals: &ReloadIntervals{
  28. Array: 15 * time.Second,
  29. Hosts: 15 * time.Second,
  30. Directories: 15 * time.Second,
  31. Pods: 15 * time.Second,
  32. Volumes: 15 * time.Second,
  33. },
  34. },
  35. },
  36. },
  37. }
  38. for _, tt := range tests {
  39. t.Run(tt.id.String(), func(t *testing.T) {
  40. factory := NewFactory()
  41. cfg := factory.CreateDefaultConfig()
  42. sub, err := cm.Sub(tt.id.String())
  43. require.NoError(t, err)
  44. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  45. assert.NoError(t, component.ValidateConfig(cfg))
  46. assert.Equal(t, tt.expected, cfg)
  47. expected := factory.CreateDefaultConfig().(*Config)
  48. require.Equal(t, expected, cfg)
  49. })
  50. }
  51. }