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

68 lines
2.3 KiB
Go

package datastoretracesexporter
import (
"path"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/zeebo/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configoptional"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"github.com/hanzoai/otel-collector/exporter/datastoretracesexporter/internal/metadata"
)
// TestLoadConfig checks whether yaml configuration can be loaded correctly
func Test_loadConfig(t *testing.T) {
factories, err := otelcoltest.NopFactories()
assert.NoError(t, err)
factory := NewFactory()
factories.Exporters[metadata.Type] = factory
cfg, err := otelcoltest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)
// From the default configurations -- checks if a correct exporter is instantiated
e0 := cfg.Exporters[(component.NewID(metadata.Type))]
defaultCfg := factory.CreateDefaultConfig()
defaultCfg.(*Config).Datasource = "tcp://127.0.0.1:9000/?database=o11y_traces&username=admin&password=password"
assert.Equal(t, e0, defaultCfg)
// checks if the correct Config struct can be instantiated from testdata/config.yaml
e1 := cfg.Exporters[component.NewIDWithName(metadata.Type, "2")]
actualCfg := e1.(*Config)
expectedBatch := configoptional.Default(exporterhelper.BatchConfig{
FlushTimeout: 200 * time.Millisecond,
Sizer: exporterhelper.RequestSizerTypeItems,
MinSize: 8192,
})
assert.Equal(t, &Config{
Timeout: 5 * time.Second,
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
InitialInterval: 5 * time.Second,
MaxInterval: 30 * time.Second,
MaxElapsedTime: 300 * time.Second,
RandomizationFactor: 0.7,
Multiplier: 1.3,
},
QueueBatchConfig: configoptional.Some(exporterhelper.QueueBatchConfig{
Sizer: exporterhelper.RequestSizerTypeRequests,
NumConsumers: 5,
QueueSize: 100,
Batch: expectedBatch,
}),
Datasource: "tcp://127.0.0.1:9000/?database=o11y_traces&username=admin&password=password",
AttributesLimits: AttributesLimits{
FetchKeysInterval: 10 * time.Minute,
MaxDistinctValues: 25000,
},
}, actualCfg)
}