config_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package activedirectorydsreceiver
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "github.com/google/go-cmp/cmp"
  9. "github.com/google/go-cmp/cmp/cmpopts"
  10. "github.com/stretchr/testify/assert"
  11. "github.com/stretchr/testify/require"
  12. "go.opentelemetry.io/collector/component"
  13. "go.opentelemetry.io/collector/confmap/confmaptest"
  14. "go.opentelemetry.io/collector/receiver/scraperhelper"
  15. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/activedirectorydsreceiver/internal/metadata"
  16. )
  17. func TestLoadConfig(t *testing.T) {
  18. t.Parallel()
  19. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  20. require.NoError(t, err)
  21. overriddenMetricsBuilderConfig := metadata.DefaultMetricsBuilderConfig()
  22. overriddenMetricsBuilderConfig.Metrics.ActiveDirectoryDsReplicationObjectRate.Enabled = false
  23. tests := []struct {
  24. id component.ID
  25. expected component.Config
  26. }{
  27. {
  28. id: component.NewIDWithName(metadata.Type, "defaults"),
  29. expected: createDefaultConfig(),
  30. },
  31. {
  32. id: component.NewIDWithName(metadata.Type, ""),
  33. expected: &Config{
  34. ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
  35. CollectionInterval: 2 * time.Minute,
  36. InitialDelay: time.Second,
  37. },
  38. MetricsBuilderConfig: overriddenMetricsBuilderConfig,
  39. },
  40. },
  41. }
  42. for _, tt := range tests {
  43. t.Run(tt.id.String(), func(t *testing.T) {
  44. factory := NewFactory()
  45. cfg := factory.CreateDefaultConfig()
  46. sub, err := cm.Sub(tt.id.String())
  47. require.NoError(t, err)
  48. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  49. assert.NoError(t, component.ValidateConfig(cfg))
  50. if diff := cmp.Diff(tt.expected, cfg, cmpopts.IgnoreUnexported(metadata.MetricsBuilderConfig{}), cmpopts.IgnoreUnexported(metadata.MetricConfig{})); diff != "" {
  51. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  52. }
  53. })
  54. }
  55. }