config_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package skywalkingreceiver
  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/config/configgrpc"
  11. "go.opentelemetry.io/collector/config/confighttp"
  12. "go.opentelemetry.io/collector/config/confignet"
  13. "go.opentelemetry.io/collector/confmap/confmaptest"
  14. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver/internal/metadata"
  15. )
  16. func TestLoadConfig(t *testing.T) {
  17. t.Parallel()
  18. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  19. require.NoError(t, err)
  20. tests := []struct {
  21. id component.ID
  22. expected component.Config
  23. }{
  24. {
  25. id: component.NewIDWithName(metadata.Type, ""),
  26. expected: createDefaultConfig(),
  27. },
  28. {
  29. id: component.NewIDWithName(metadata.Type, "customname"),
  30. expected: &Config{
  31. Protocols: Protocols{
  32. HTTP: &confighttp.HTTPServerSettings{
  33. Endpoint: "0.0.0.0:12801",
  34. },
  35. },
  36. },
  37. },
  38. {
  39. id: component.NewIDWithName(metadata.Type, "defaults"),
  40. expected: &Config{
  41. Protocols: Protocols{
  42. GRPC: &configgrpc.GRPCServerSettings{
  43. NetAddr: confignet.NetAddr{
  44. Endpoint: defaultGRPCBindEndpoint,
  45. Transport: "tcp",
  46. },
  47. },
  48. },
  49. },
  50. },
  51. }
  52. for _, tt := range tests {
  53. t.Run(tt.id.String(), func(t *testing.T) {
  54. factory := NewFactory()
  55. cfg := factory.CreateDefaultConfig()
  56. sub, err := cm.Sub(tt.id.String())
  57. require.NoError(t, err)
  58. require.NoError(t, component.UnmarshalConfig(sub, cfg))
  59. assert.NoError(t, component.ValidateConfig(cfg))
  60. assert.Equal(t, tt.expected, cfg)
  61. })
  62. }
  63. }