mirror of
https://github.com/hanzoai/otel-collector.git
synced 2026-11-03 02:20:04 +00:00
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]>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package o11yawsfirehosereceiver
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/config/confignet"
|
|
"go.opentelemetry.io/collector/config/configoptional"
|
|
"go.opentelemetry.io/collector/config/configtls"
|
|
"go.opentelemetry.io/collector/confmap/confmaptest"
|
|
"go.opentelemetry.io/collector/confmap/xconfmap"
|
|
|
|
"github.com/hanzoai/otel-collector/receiver/o11yawsfirehosereceiver/internal/metadata"
|
|
)
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
for _, configType := range []string{
|
|
"cwmetrics", "cwlogs", "otlp_v1", "invalid",
|
|
} {
|
|
t.Run(configType, func(t *testing.T) {
|
|
fileName := configType + "_config.yaml"
|
|
cm, err := confmaptest.LoadConf(filepath.Join("testdata", fileName))
|
|
require.NoError(t, err)
|
|
|
|
factory := NewFactory()
|
|
cfg := factory.CreateDefaultConfig()
|
|
|
|
sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
|
|
require.NoError(t, err)
|
|
require.NoError(t, sub.Unmarshal(cfg))
|
|
|
|
err = xconfmap.Validate(cfg)
|
|
if configType == "invalid" {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
require.Equal(t, &Config{
|
|
RecordType: configType,
|
|
NetAddr: confignet.AddrConfig{
|
|
Endpoint: "0.0.0.0:4433",
|
|
Transport: "tcp",
|
|
},
|
|
TLS: configoptional.Some(configtls.ServerConfig{
|
|
CertFile: "server.crt",
|
|
KeyFile: "server.key",
|
|
}),
|
|
}, cfg)
|
|
}
|
|
})
|
|
}
|
|
}
|