feat service: introduce labels for logs/recorder (#104)

This commit is contained in:
Denis Galeev
2026-06-13 08:05:14 +03:00
committed by GitHub
parent eaeac2763e
commit 9f610fd163
6 changed files with 81 additions and 10 deletions
+24
View File
@@ -3,6 +3,7 @@ package ctx
import (
"context"
"net"
"reflect"
"testing"
)
@@ -149,6 +150,29 @@ func TestClientIDFromContext_WrongType(t *testing.T) {
}
}
func TestContextWithLabels(t *testing.T) {
labels := map[string]string{"tenant": "acme", "region": "eu"}
ctx := ContextWithLabels(context.Background(), labels)
got := LabelsFromContext(ctx)
if !reflect.DeepEqual(got, labels) {
t.Errorf("LabelsFromContext() = %v, want %v", got, labels)
}
}
func TestLabelsFromContext_Empty(t *testing.T) {
if got := LabelsFromContext(context.Background()); got != nil {
t.Errorf("LabelsFromContext(empty) = %v, want nil", got)
}
}
func TestLabelsFromContext_WrongType(t *testing.T) {
ctx := context.WithValue(context.Background(), labelsKey{}, "not-a-map")
if got := LabelsFromContext(ctx); got != nil {
t.Errorf("LabelsFromContext(wrong type) = %v, want nil", got)
}
}
func TestMultipleValuesInContext(t *testing.T) {
ctx := context.Background()
ctx = ContextWithSrcAddr(ctx, &net.TCPAddr{IP: net.ParseIP("10.0.0.1"), Port: 8080})