mirror of
https://github.com/hanzoai/otel-collector.git
synced 2026-11-02 13:34:59 +00:00
- Go module: github.com/SigNoz/signoz-otel-collector → github.com/hanzoai/otel-collector - All signoz-prefixed packages → o11y-prefixed - Docker: signoz/* → ghcr.io/hanzoai/otel-collector - ClickHouse exporter → Hanzo Datastore - Env vars: SIGNOZ_* → HANZO_* - Directory renames for all processor/receiver/exporter packages
140 lines
3.4 KiB
Go
140 lines
3.4 KiB
Go
package httplogreceiver
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/otel-collector/receiver/httplogreceiver/internal/metadata"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/config/confighttp"
|
|
"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"
|
|
)
|
|
|
|
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: createDefaultConfig(),
|
|
},
|
|
{
|
|
id: component.NewIDWithName(metadata.Type, "endpoint"),
|
|
expected: &Config{
|
|
ServerConfig: confighttp.ServerConfig{
|
|
NetAddr: confignet.AddrConfig{
|
|
Endpoint: "localhost:54321",
|
|
Transport: "tcp",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
id: component.NewIDWithName(metadata.Type, "withtls"),
|
|
expected: &Config{
|
|
ServerConfig: confighttp.ServerConfig{
|
|
NetAddr: confignet.AddrConfig{
|
|
Endpoint: ":54321",
|
|
Transport: "tcp",
|
|
},
|
|
TLS: configoptional.Some(configtls.ServerConfig{
|
|
Config: configtls.Config{
|
|
CertFile: "/test.crt",
|
|
KeyFile: "/test.key",
|
|
},
|
|
}),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
id: component.NewIDWithName(metadata.Type, "heroku"),
|
|
expected: &Config{
|
|
ServerConfig: confighttp.ServerConfig{
|
|
NetAddr: confignet.AddrConfig{
|
|
Endpoint: ":54321",
|
|
Transport: "tcp",
|
|
},
|
|
},
|
|
Source: "heroku",
|
|
},
|
|
},
|
|
{
|
|
id: component.NewIDWithName(metadata.Type, "google"),
|
|
expected: &Config{
|
|
ServerConfig: confighttp.ServerConfig{
|
|
NetAddr: confignet.AddrConfig{
|
|
Endpoint: ":54321",
|
|
Transport: "tcp",
|
|
},
|
|
},
|
|
Source: "google",
|
|
},
|
|
},
|
|
{
|
|
id: component.NewIDWithName(metadata.Type, "json"),
|
|
expected: &Config{
|
|
ServerConfig: confighttp.ServerConfig{
|
|
NetAddr: confignet.AddrConfig{
|
|
Endpoint: ":54321",
|
|
Transport: "tcp",
|
|
},
|
|
},
|
|
Source: "json",
|
|
},
|
|
},
|
|
}
|
|
|
|
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)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCreateInvalidHTTPEndpoint(t *testing.T) {
|
|
factory := NewFactory()
|
|
cfg := factory.CreateDefaultConfig().(*Config)
|
|
cfg.NetAddr.Endpoint = ""
|
|
|
|
err := cfg.Validate()
|
|
assert.EqualError(t, err, "must specify an endpoint for the httplogreceiver")
|
|
}
|
|
|
|
func TestCreateNoPortEndpoint(t *testing.T) {
|
|
factory := NewFactory()
|
|
cfg := factory.CreateDefaultConfig().(*Config)
|
|
cfg.NetAddr.Endpoint = "localhost:"
|
|
|
|
err := cfg.Validate()
|
|
assert.EqualError(t, err, `endpoint port is not a number: strconv.ParseInt: parsing "": invalid syntax`)
|
|
}
|
|
|
|
func TestCreateLargePortEndpoint(t *testing.T) {
|
|
factory := NewFactory()
|
|
cfg := factory.CreateDefaultConfig().(*Config)
|
|
cfg.NetAddr.Endpoint = "localhost:65536"
|
|
|
|
err := cfg.Validate()
|
|
assert.EqualError(t, err, "port number must be between 1 and 65535")
|
|
}
|