feat: game lobby service
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package logging_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"galaxy/lobby/internal/logging"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func TestRequestIDRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := logging.WithRequestID(context.Background(), "rid-1")
|
||||
assert.Equal(t, "rid-1", logging.RequestIDFromContext(ctx))
|
||||
|
||||
assert.Equal(t, "", logging.RequestIDFromContext(context.Background()))
|
||||
}
|
||||
|
||||
func TestWithRequestIDIgnoresEmptyValue(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
parent := context.Background()
|
||||
ctx := logging.WithRequestID(parent, "")
|
||||
assert.Equal(t, parent, ctx)
|
||||
}
|
||||
|
||||
func TestContextAttrsIncludesRequestID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := logging.WithRequestID(context.Background(), "rid-2")
|
||||
attrs := logging.ContextAttrs(ctx)
|
||||
require.Contains(t, attrs, "request_id")
|
||||
require.Contains(t, attrs, "rid-2")
|
||||
}
|
||||
|
||||
func TestContextAttrsIncludesTraceID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
traceID, err := trace.TraceIDFromHex("0123456789abcdef0123456789abcdef")
|
||||
require.NoError(t, err)
|
||||
spanID, err := trace.SpanIDFromHex("fedcba9876543210")
|
||||
require.NoError(t, err)
|
||||
spanContext := trace.NewSpanContext(trace.SpanContextConfig{
|
||||
TraceID: traceID,
|
||||
SpanID: spanID,
|
||||
})
|
||||
ctx := trace.ContextWithSpanContext(context.Background(), spanContext)
|
||||
|
||||
attrs := logging.ContextAttrs(ctx)
|
||||
require.Contains(t, attrs, "trace_id")
|
||||
require.Contains(t, attrs, traceID.String())
|
||||
require.Contains(t, attrs, "span_id")
|
||||
require.Contains(t, attrs, spanID.String())
|
||||
}
|
||||
|
||||
func TestContextAttrsEmptyContextReturnsNil(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.Nil(t, logging.ContextAttrs(context.Background()))
|
||||
}
|
||||
Reference in New Issue
Block a user