updates Go dependencies, refactors and expands unit tests for config, logging, OpenTelemetry, HTTP, and gRPC components

This commit is contained in:
2025-09-02 13:06:02 -04:00
parent 8d6297a0cb
commit c7e42a7544
9 changed files with 578 additions and 193 deletions

66
pkg/otel/otel_test.go Normal file
View 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())
})
}