updates Go dependencies, refactors and expands unit tests for config, logging, OpenTelemetry, HTTP, and gRPC components
This commit is contained in:
66
pkg/otel/otel_test.go
Normal file
66
pkg/otel/otel_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
package otel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.opentelemetry.io/otel/metric/noop"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
cfg := &config.AppConfig{
|
||||
Name: "test-app",
|
||||
OTEL: &config.OTELConfig{
|
||||
Enabled: true,
|
||||
},
|
||||
}
|
||||
ctx := cfg.AddToCtx(context.Background())
|
||||
|
||||
ctx, shutdown := Init(ctx)
|
||||
defer shutdown(context.Background())
|
||||
|
||||
assert.NotNil(t, ctx.Value(ctxKeyTracer))
|
||||
assert.NotNil(t, ctx.Value(ctxKeyMeter))
|
||||
}
|
||||
|
||||
func TestInit_Disabled(t *testing.T) {
|
||||
cfg := &config.AppConfig{
|
||||
Name: "test-app",
|
||||
OTEL: &config.OTELConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
}
|
||||
ctx := cfg.AddToCtx(context.Background())
|
||||
|
||||
ctx, shutdown := Init(ctx)
|
||||
defer shutdown(context.Background())
|
||||
|
||||
assert.NotNil(t, ctx.Value(ctxKeyTracer))
|
||||
assert.NotNil(t, ctx.Value(ctxKeyMeter))
|
||||
}
|
||||
|
||||
func TestContextFuncs(t *testing.T) {
|
||||
tracer := trace.NewNoopTracerProvider().Tracer("test")
|
||||
meter := noop.NewMeterProvider().Meter("test")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = AddTracerToCtx(ctx, tracer)
|
||||
ctx = AddMeterToCtx(ctx, meter)
|
||||
|
||||
assert.Equal(t, tracer, MustTracerFromCtx(ctx))
|
||||
assert.Equal(t, meter, MustMeterFromCtx(ctx))
|
||||
}
|
||||
|
||||
func TestContextFuncs_Panic(t *testing.T) {
|
||||
assert.Panics(t, func() {
|
||||
MustTracerFromCtx(context.Background())
|
||||
})
|
||||
assert.Panics(t, func() {
|
||||
MustMeterFromCtx(context.Background())
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user