configs_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package configschema
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. "go.opentelemetry.io/collector/otelcol"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/components"
  9. )
  10. func TestGetAllConfigs(t *testing.T) {
  11. cfgs := GetAllCfgInfos(testComponents())
  12. require.NotNil(t, cfgs)
  13. }
  14. func TestCreateReceiverConfig(t *testing.T) {
  15. cfg, err := GetCfgInfo(testComponents(), "receiver", "otlp")
  16. require.NoError(t, err)
  17. require.NotNil(t, cfg)
  18. }
  19. func TestCreateProcesorConfig(t *testing.T) {
  20. cfg, err := GetCfgInfo(testComponents(), "processor", "filter")
  21. require.NoError(t, err)
  22. require.NotNil(t, cfg)
  23. }
  24. func TestGetConfig(t *testing.T) {
  25. tests := []struct {
  26. name string
  27. componentType string
  28. }{
  29. {
  30. name: "otlp",
  31. componentType: "receiver",
  32. },
  33. {
  34. name: "filter",
  35. componentType: "processor",
  36. },
  37. {
  38. name: "otlp",
  39. componentType: "exporter",
  40. },
  41. {
  42. name: "zpages",
  43. componentType: "extension",
  44. },
  45. }
  46. for _, test := range tests {
  47. t.Run(test.name, func(t *testing.T) {
  48. cfg, err := GetCfgInfo(testComponents(), test.componentType, test.name)
  49. require.NoError(t, err)
  50. require.NotNil(t, cfg)
  51. })
  52. }
  53. }
  54. func testComponents() otelcol.Factories {
  55. cmps, err := components.Components()
  56. if err != nil {
  57. panic(err)
  58. }
  59. return cmps
  60. }