Files
zeekayandHanzo Dev c16ed9fe26 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 02:34:35 -07:00

100 lines
3.0 KiB
Go

package metadataexporter
import (
"path/filepath"
"testing"
"time"
"github.com/hanzoai/otel-collector/exporter/metadataexporter/internal/metadata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/confmap/xconfmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)
func TestLoadConfig(t *testing.T) {
t.Parallel()
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)
tests := []struct {
id component.ID
expected component.Config
}{
{
id: component.NewIDWithName(metadata.Type, ""),
expected: &Config{
TimeoutConfig: exporterhelper.NewDefaultTimeoutConfig(),
BackOffConfig: configretry.NewDefaultBackOffConfig(),
QueueBatchConfig: configoptional.Some(exporterhelper.NewDefaultQueueConfig()),
DSN: "tcp://localhost:9000",
MaxDistinctValues: MaxDistinctValuesConfig{
Traces: LimitsConfig{
MaxKeys: 100,
MaxStringLength: 128,
MaxStringDistinctValues: 420,
FetchInterval: 5 * time.Minute,
},
Logs: LimitsConfig{
MaxKeys: 100,
MaxStringLength: 64,
MaxStringDistinctValues: 512,
FetchInterval: 10 * time.Minute,
},
Metrics: LimitsConfig{
MaxKeys: 100,
MaxStringLength: 16,
MaxStringDistinctValues: 1024,
FetchInterval: 5 * time.Minute,
},
},
Cache: CacheConfig{
Provider: CacheProviderInMemory,
InMemory: InMemoryCacheConfig{},
Traces: CacheLimits{
MaxResources: DefaultMaxResources,
MaxCardinalityPerResource: DefaultMaxCardinalityPerResource,
MaxTotalCardinality: DefaultMaxTotalCardinality,
},
Metrics: CacheLimits{
MaxResources: DefaultMaxResources,
MaxCardinalityPerResource: DefaultMaxCardinalityPerResource,
MaxTotalCardinality: DefaultMaxTotalCardinality,
},
Logs: CacheLimits{
MaxResources: DefaultMaxResources,
MaxCardinalityPerResource: DefaultMaxCardinalityPerResource,
MaxTotalCardinality: DefaultMaxTotalCardinality,
},
},
Enabled: false,
JSON: JSONConfig{
Enabled: true,
MaxDepthTraverse: new(defaultJSONMaxDepthTraverse),
MaxArrayElementsAllowed: new(defaultJSONMaxArrayElementsAllowed),
MaxKeysAtLevel: new(100),
},
},
},
}
for _, tt := range tests {
t.Run(tt.id.String(), func(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
sub, err := cm.Sub(tt.id.String())
require.NoError(t, err)
require.NoError(t, sub.Unmarshal(cfg))
assert.NoError(t, xconfmap.Validate(cfg))
assert.Equal(t, tt.expected, cfg)
})
}
}