generated_config_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Code generated by mdatagen. DO NOT EDIT.
  2. package metadata
  3. import (
  4. "path/filepath"
  5. "testing"
  6. "github.com/google/go-cmp/cmp"
  7. "github.com/google/go-cmp/cmp/cmpopts"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/confmap/confmaptest"
  11. )
  12. func TestMetricsBuilderConfig(t *testing.T) {
  13. tests := []struct {
  14. name string
  15. want MetricsBuilderConfig
  16. }{
  17. {
  18. name: "default",
  19. want: DefaultMetricsBuilderConfig(),
  20. },
  21. {
  22. name: "all_set",
  23. want: MetricsBuilderConfig{
  24. Metrics: MetricsConfig{
  25. SshcheckDuration: MetricConfig{Enabled: true},
  26. SshcheckError: MetricConfig{Enabled: true},
  27. SshcheckSftpDuration: MetricConfig{Enabled: true},
  28. SshcheckSftpError: MetricConfig{Enabled: true},
  29. SshcheckSftpStatus: MetricConfig{Enabled: true},
  30. SshcheckStatus: MetricConfig{Enabled: true},
  31. },
  32. ResourceAttributes: ResourceAttributesConfig{
  33. SSHEndpoint: ResourceAttributeConfig{Enabled: true},
  34. },
  35. },
  36. },
  37. {
  38. name: "none_set",
  39. want: MetricsBuilderConfig{
  40. Metrics: MetricsConfig{
  41. SshcheckDuration: MetricConfig{Enabled: false},
  42. SshcheckError: MetricConfig{Enabled: false},
  43. SshcheckSftpDuration: MetricConfig{Enabled: false},
  44. SshcheckSftpError: MetricConfig{Enabled: false},
  45. SshcheckSftpStatus: MetricConfig{Enabled: false},
  46. SshcheckStatus: MetricConfig{Enabled: false},
  47. },
  48. ResourceAttributes: ResourceAttributesConfig{
  49. SSHEndpoint: ResourceAttributeConfig{Enabled: false},
  50. },
  51. },
  52. },
  53. }
  54. for _, tt := range tests {
  55. t.Run(tt.name, func(t *testing.T) {
  56. cfg := loadMetricsBuilderConfig(t, tt.name)
  57. if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})); diff != "" {
  58. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  59. }
  60. })
  61. }
  62. }
  63. func loadMetricsBuilderConfig(t *testing.T, name string) MetricsBuilderConfig {
  64. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  65. require.NoError(t, err)
  66. sub, err := cm.Sub(name)
  67. require.NoError(t, err)
  68. cfg := DefaultMetricsBuilderConfig()
  69. require.NoError(t, component.UnmarshalConfig(sub, &cfg))
  70. return cfg
  71. }
  72. func TestResourceAttributesConfig(t *testing.T) {
  73. tests := []struct {
  74. name string
  75. want ResourceAttributesConfig
  76. }{
  77. {
  78. name: "default",
  79. want: DefaultResourceAttributesConfig(),
  80. },
  81. {
  82. name: "all_set",
  83. want: ResourceAttributesConfig{
  84. SSHEndpoint: ResourceAttributeConfig{Enabled: true},
  85. },
  86. },
  87. {
  88. name: "none_set",
  89. want: ResourceAttributesConfig{
  90. SSHEndpoint: ResourceAttributeConfig{Enabled: false},
  91. },
  92. },
  93. }
  94. for _, tt := range tests {
  95. t.Run(tt.name, func(t *testing.T) {
  96. cfg := loadResourceAttributesConfig(t, tt.name)
  97. if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" {
  98. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  99. }
  100. })
  101. }
  102. }
  103. func loadResourceAttributesConfig(t *testing.T, name string) ResourceAttributesConfig {
  104. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  105. require.NoError(t, err)
  106. sub, err := cm.Sub(name)
  107. require.NoError(t, err)
  108. sub, err = sub.Sub("resource_attributes")
  109. require.NoError(t, err)
  110. cfg := DefaultResourceAttributesConfig()
  111. require.NoError(t, component.UnmarshalConfig(sub, &cfg))
  112. return cfg
  113. }