generated from TrueCloudLab/basic
Aleksey Savaitan
db6cf1ea16
All checks were successful
DCO action / DCO (pull_request) Successful in 45s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m38s
Tests and linters / Tests (1.22) (pull_request) Successful in 1m38s
Tests and linters / Tests with -race (pull_request) Successful in 1m42s
Tests and linters / Staticcheck (pull_request) Successful in 1m50s
Tests and linters / Lint (pull_request) Successful in 2m0s
Signed-off-by: Aleksey Savaitan <a.savaitan@yadro.com>
264 lines
5.3 KiB
Go
264 lines
5.3 KiB
Go
package tracing
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestConfig_validate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
config Config
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "disabled",
|
|
wantErr: false,
|
|
config: Config{
|
|
Enabled: false,
|
|
},
|
|
},
|
|
{
|
|
name: "stdout",
|
|
wantErr: false,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: StdoutExporter,
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
{
|
|
name: "noop",
|
|
wantErr: false,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: StdoutExporter,
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
{
|
|
name: "OTLP gRPC",
|
|
wantErr: false,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Service: "test",
|
|
Endpoint: "localhost:4717",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
{
|
|
name: "unknown exporter",
|
|
wantErr: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: "unknown",
|
|
Service: "test",
|
|
Endpoint: "localhost:4717",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
{
|
|
name: "no exporter",
|
|
wantErr: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Service: "test",
|
|
Endpoint: "localhost:4717",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
{
|
|
name: "no service",
|
|
wantErr: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
{
|
|
name: "no endpoint for grpc",
|
|
wantErr: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v0.0.1",
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := tt.config.validate(); (err != nil) != tt.wantErr {
|
|
t.Errorf("Config.validate() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestConfig_hasChange(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
config Config
|
|
other Config
|
|
want bool
|
|
}{
|
|
{
|
|
name: "disabled configs always equal",
|
|
want: false,
|
|
config: Config{
|
|
Enabled: false,
|
|
Exporter: StdoutExporter,
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: false,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
},
|
|
{
|
|
name: "enabled",
|
|
want: true,
|
|
config: Config{
|
|
Enabled: false,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
},
|
|
{
|
|
name: "disabled",
|
|
want: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: false,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
},
|
|
{
|
|
name: "do not use endpoint for stdout",
|
|
want: false,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: StdoutExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: true,
|
|
Exporter: StdoutExporter,
|
|
Endpoint: "otherhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
},
|
|
{
|
|
name: "do not use endpoint for noop",
|
|
want: false,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: NoOpExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: true,
|
|
Exporter: NoOpExporter,
|
|
Endpoint: "otherhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
},
|
|
{
|
|
name: "use endpoint for grpc",
|
|
want: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "otherhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
},
|
|
{
|
|
name: "use tls root ca certificate for grpc",
|
|
want: true,
|
|
config: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
},
|
|
other: Config{
|
|
Enabled: true,
|
|
Exporter: OTLPgRPCExporter,
|
|
Endpoint: "localhost:4717",
|
|
Service: "test",
|
|
InstanceID: "s01",
|
|
Version: "v1.0.0",
|
|
ServerCaCertPath: "/etc/ssl/test_ca.pem",
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.config.hasChange(&tt.other); got != tt.want {
|
|
t.Errorf("Config.equal() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|