config_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package zipkinexporter
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "github.com/cenkalti/backoff/v4"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. "go.opentelemetry.io/collector/component"
  12. "go.opentelemetry.io/collector/config/confighttp"
  13. "go.opentelemetry.io/collector/config/configtls"
  14. "go.opentelemetry.io/collector/confmap/confmaptest"
  15. "go.opentelemetry.io/collector/exporter/exporterhelper"
  16. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/zipkinexporter/internal/metadata"
  17. )
  18. func TestLoadConfig(t *testing.T) {
  19. t.Parallel()
  20. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  21. require.NoError(t, err)
  22. // URL doesn't have a default value so set it directly.
  23. defaultCfg := createDefaultConfig().(*Config)
  24. defaultCfg.Endpoint = "http://some.location.org:9411/api/v2/spans"
  25. tests := []struct {
  26. id component.ID
  27. expected component.Config
  28. }{
  29. {
  30. id: component.NewIDWithName(metadata.Type, ""),
  31. expected: defaultCfg,
  32. },
  33. {
  34. id: component.NewIDWithName(metadata.Type, "2"),
  35. expected: &Config{
  36. RetrySettings: exporterhelper.RetrySettings{
  37. Enabled: true,
  38. InitialInterval: 10 * time.Second,
  39. MaxInterval: 1 * time.Minute,
  40. MaxElapsedTime: 10 * time.Minute,
  41. RandomizationFactor: backoff.DefaultRandomizationFactor,
  42. Multiplier: backoff.DefaultMultiplier,
  43. },
  44. QueueSettings: exporterhelper.QueueSettings{
  45. Enabled: true,
  46. NumConsumers: 2,
  47. QueueSize: 10,
  48. },
  49. HTTPClientSettings: confighttp.HTTPClientSettings{
  50. Endpoint: "https://somedest:1234/api/v2/spans",
  51. WriteBufferSize: 524288,
  52. Timeout: 5 * time.Second,
  53. TLSSetting: configtls.TLSClientSetting{
  54. InsecureSkipVerify: true,
  55. },
  56. },
  57. Format: "proto",
  58. DefaultServiceName: "test_name",
  59. },
  60. },
  61. }
  62. for _, tt := range tests {
  63. t.Run(tt.id.String(), func(t *testing.T) {
  64. factory := NewFactory()
  65. cfg := factory.CreateDefaultConfig()
  66. sub, err := cm.Sub(tt.id.String())
  67. require.NoError(t, err)
  68. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  69. assert.NoError(t, component.ValidateConfig(cfg))
  70. assert.Equal(t, tt.expected, cfg)
  71. })
  72. }
  73. }