config_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awsecscontainermetricsreceiver
  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/awsecscontainermetricsreceiver/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.NewIDWithName(metadata.Type, ""),
  24. expected: createDefaultConfig(),
  25. },
  26. {
  27. id: component.NewIDWithName(metadata.Type, "collection_interval_settings"),
  28. expected: &Config{
  29. CollectionInterval: 10 * time.Second,
  30. },
  31. },
  32. }
  33. for _, tt := range tests {
  34. t.Run(tt.id.String(), func(t *testing.T) {
  35. factory := NewFactory()
  36. cfg := factory.CreateDefaultConfig()
  37. sub, err := cm.Sub(tt.id.String())
  38. require.NoError(t, err)
  39. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  40. assert.NoError(t, component.ValidateConfig(cfg))
  41. assert.Equal(t, tt.expected, cfg)
  42. })
  43. }
  44. }