config_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package wavefrontreceiver
  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/confmap/confmaptest"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver/internal/metadata"
  14. )
  15. func TestLoadConfig(t *testing.T) {
  16. t.Parallel()
  17. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  18. require.NoError(t, err)
  19. tests := []struct {
  20. id component.ID
  21. expected component.Config
  22. }{
  23. {
  24. id: component.NewID(metadata.Type),
  25. expected: createDefaultConfig(),
  26. },
  27. {
  28. id: component.NewIDWithName(metadata.Type, "allsettings"),
  29. expected: &Config{
  30. TCPAddr: confignet.TCPAddr{
  31. Endpoint: "localhost:8080",
  32. },
  33. TCPIdleTimeout: 5 * time.Second,
  34. ExtractCollectdTags: true,
  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. })
  48. }
  49. }