config_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awscontainerinsightreceiver
  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/awscontainerinsightreceiver/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: 60 * time.Second,
  30. ContainerOrchestrator: "eks",
  31. TagService: true,
  32. PrefFullPodName: false,
  33. },
  34. },
  35. }
  36. for _, tt := range tests {
  37. t.Run(tt.id.String(), func(t *testing.T) {
  38. factory := NewFactory()
  39. cfg := factory.CreateDefaultConfig()
  40. sub, err := cm.Sub(tt.id.String())
  41. require.NoError(t, err)
  42. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  43. assert.NoError(t, component.ValidateConfig(cfg))
  44. assert.Equal(t, tt.expected, cfg)
  45. })
  46. }
  47. }