config_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package tencentcloudlogserviceexporter
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/confmap/confmaptest"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/tencentcloudlogserviceexporter/internal/metadata"
  12. )
  13. func TestLoadConfig(t *testing.T) {
  14. t.Parallel()
  15. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  16. require.NoError(t, err)
  17. tests := []struct {
  18. id component.ID
  19. expected component.Config
  20. }{
  21. {
  22. id: component.NewIDWithName(metadata.Type, "2"),
  23. expected: &Config{
  24. Region: "ap-beijing",
  25. LogSet: "demo-logset",
  26. Topic: "demo-topic",
  27. SecretID: "demo-secret-id",
  28. SecretKey: "demo-secret-key",
  29. },
  30. },
  31. }
  32. for _, tt := range tests {
  33. t.Run(tt.id.String(), func(t *testing.T) {
  34. factory := NewFactory()
  35. cfg := factory.CreateDefaultConfig()
  36. sub, err := cm.Sub(tt.id.String())
  37. require.NoError(t, err)
  38. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  39. assert.NoError(t, component.ValidateConfig(cfg))
  40. assert.Equal(t, tt.expected, cfg)
  41. })
  42. }
  43. }