config_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package memcachedreceiver
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "github.com/stretchr/testify/require"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/confmap/confmaptest"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/memcachedreceiver/internal/metadata"
  11. )
  12. func TestDefaultConfig(t *testing.T) {
  13. cfg := NewFactory().CreateDefaultConfig().(*Config)
  14. require.Equal(t, defaultEndpoint, cfg.Endpoint)
  15. require.Equal(t, defaultTimeout, cfg.Timeout)
  16. require.Equal(t, defaultCollectionInterval, cfg.CollectionInterval)
  17. }
  18. func TestLoadConfig(t *testing.T) {
  19. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  20. require.NoError(t, err)
  21. factory := NewFactory()
  22. cfg := factory.CreateDefaultConfig()
  23. sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
  24. require.NoError(t, err)
  25. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  26. require.Equal(t, factory.CreateDefaultConfig(), cfg)
  27. }