comments_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package configschema
  4. import (
  5. "reflect"
  6. "testing"
  7. "github.com/google/uuid"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. "go.opentelemetry.io/collector/config/configtls"
  11. )
  12. func TestFieldComments(t *testing.T) {
  13. v := reflect.ValueOf(testStruct{})
  14. comments, err := commentsForStruct(v, testDR())
  15. assert.NoError(t, err)
  16. assert.Equal(t, "embedded, package qualified comment\n", comments["Duration"])
  17. assert.Equal(t, "testStruct comment\n", comments["_struct"])
  18. }
  19. func TestExternalType(t *testing.T) {
  20. u, err := uuid.NewUUID()
  21. assert.NoError(t, err)
  22. v := reflect.ValueOf(u)
  23. comments, err := commentsForStruct(v, testDR())
  24. assert.NoError(t, err)
  25. assert.Equal(
  26. t,
  27. "A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC\n4122.\n",
  28. comments["_struct"],
  29. )
  30. }
  31. func TestSubPackage(t *testing.T) {
  32. s := configtls.TLSClientSetting{}
  33. v := reflect.ValueOf(s)
  34. _, err := commentsForStruct(v, testDR())
  35. require.NoError(t, err)
  36. }