generated from TrueCloudLab/basic
122 lines
3.3 KiB
Go
122 lines
3.3 KiB
Go
|
package tracing_test
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
"testing"
|
||
|
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/testdata"
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
||
|
)
|
||
|
|
||
|
func TestSetup(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
config tracing.Config
|
||
|
want bool
|
||
|
expErr error
|
||
|
}{
|
||
|
{
|
||
|
name: "setup stdout exporter",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.StdoutExporter,
|
||
|
Service: "service-name",
|
||
|
},
|
||
|
want: true,
|
||
|
expErr: nil,
|
||
|
},
|
||
|
{
|
||
|
name: "setup noop exporter",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.NoOpExporter,
|
||
|
Service: "service-name",
|
||
|
},
|
||
|
|
||
|
want: true,
|
||
|
expErr: nil,
|
||
|
},
|
||
|
{
|
||
|
name: "setup otlp_grpc insecure exporter",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.OTLPgRPCExporter,
|
||
|
Service: "service-name",
|
||
|
Endpoint: "test-endpoint.com:4317",
|
||
|
},
|
||
|
want: true,
|
||
|
expErr: nil,
|
||
|
},
|
||
|
{
|
||
|
name: "setup otlp_grpc secure exporter with valid rsa root ca certificate",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.OTLPgRPCExporter,
|
||
|
Service: "service-name",
|
||
|
Endpoint: "test-endpoint.com:4317",
|
||
|
ServerCaCertPath: testdata.Path("tracing/setup/valid_google_globalsign_r4_rsa_root_ca.pem"),
|
||
|
},
|
||
|
want: true,
|
||
|
expErr: nil,
|
||
|
},
|
||
|
{
|
||
|
name: "setup otlp_grpc secure exporter with valid ecdsa root ca certificate",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.OTLPgRPCExporter,
|
||
|
Service: "service-name",
|
||
|
Endpoint: "test-endpoint.com:4317",
|
||
|
ServerCaCertPath: testdata.Path("tracing/setup/valid_google_gts_r4_ecdsa_root_ca.pem"),
|
||
|
},
|
||
|
want: true,
|
||
|
expErr: nil,
|
||
|
},
|
||
|
{
|
||
|
name: "setup otlp_grpc secure exporter with invalid empty root ca certificate",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.OTLPgRPCExporter,
|
||
|
Service: "service-name",
|
||
|
Endpoint: "test-endpoint.com:4317",
|
||
|
ServerCaCertPath: testdata.Path("tracing/setup/invalid_empty_root_ca.pem"),
|
||
|
},
|
||
|
want: false,
|
||
|
expErr: tracing.ErrInvalidServerRootCaCertificate,
|
||
|
},
|
||
|
{
|
||
|
name: "setup otlp_grpc secure exporter with invalid root ca certificate",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.OTLPgRPCExporter,
|
||
|
Service: "service-name",
|
||
|
Endpoint: "test-endpoint.com:4317",
|
||
|
ServerCaCertPath: testdata.Path("tracing/setup/invalid_root_ca.pem"),
|
||
|
},
|
||
|
want: false,
|
||
|
expErr: tracing.ErrInvalidServerRootCaCertificate,
|
||
|
},
|
||
|
{
|
||
|
name: "setup otlp_grpc secure exporter with invalid path root ca certificate",
|
||
|
config: tracing.Config{
|
||
|
Enabled: true,
|
||
|
Exporter: tracing.OTLPgRPCExporter,
|
||
|
Service: "service-name",
|
||
|
Endpoint: "test-endpoint.com:4317",
|
||
|
ServerCaCertPath: testdata.Path(""),
|
||
|
},
|
||
|
want: false,
|
||
|
expErr: tracing.ErrInvalidServerRootCaCertificate,
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
got, err := tracing.Setup(context.Background(), tt.config)
|
||
|
require.ErrorIs(t, err, tt.expErr)
|
||
|
if got != tt.want {
|
||
|
t.Errorf("Setup config = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|