generated from TrueCloudLab/basic
Aleksey Savaitan
666d326cc5
All checks were successful
DCO action / DCO (pull_request) Successful in 24s
Tests and linters / Tests (pull_request) Successful in 51s
Tests and linters / Tests with -race (pull_request) Successful in 1m3s
Tests and linters / Staticcheck (pull_request) Successful in 1m15s
Tests and linters / Lint (pull_request) Successful in 1m44s
Signed-off-by: Aleksey Savaitan <a.savaitan@yadro.com>
118 lines
3.1 KiB
Go
118 lines
3.1 KiB
Go
package tracing_test
|
|
|
|
import (
|
|
"context"
|
|
"crypto/x509"
|
|
"os"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
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",
|
|
ServerCaCertPool: readCertPoolByPath(t, "../testdata/tracing/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",
|
|
ServerCaCertPool: readCertPoolByPath(t, "../testdata/tracing/valid_google_gts_r4_ecdsa_root_ca.pem"),
|
|
},
|
|
want: true,
|
|
expErr: nil,
|
|
},
|
|
{
|
|
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",
|
|
ServerCaCertPool: readCertPoolByPath(t, "../testdata/tracing/invalid_root_ca.pem"),
|
|
},
|
|
want: false,
|
|
expErr: tracing.ErrEmptyServerRootCaPool,
|
|
},
|
|
{
|
|
name: "setup otlp_grpc secure exporter with empty root ca certificate",
|
|
config: tracing.Config{
|
|
Enabled: true,
|
|
Exporter: tracing.OTLPgRPCExporter,
|
|
Service: "service-name",
|
|
Endpoint: "test-endpoint.com:4317",
|
|
ServerCaCertPool: readCertPoolByPath(t, "../testdata/tracing/invalid_empty_root_ca.pem"),
|
|
},
|
|
want: false,
|
|
expErr: tracing.ErrEmptyServerRootCaPool,
|
|
},
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func readCertPoolByPath(t *testing.T, path string) *x509.CertPool {
|
|
ca, err := os.ReadFile(path)
|
|
require.NoError(t, err)
|
|
roots := x509.NewCertPool()
|
|
_ = roots.AppendCertsFromPEM(ca)
|
|
return roots
|
|
}
|