Files
uopi/internal/datasource/user_test.go
T
Martino Ferrari c0f7e662be Testing
2026-06-24 01:39:15 +02:00

29 lines
741 B
Go

package datasource
import (
"context"
"testing"
)
// TestWithUserAndUserFrom covers the context identity round-trip, including the
// empty-user passthrough and the missing-identity fallback.
func TestWithUserAndUserFrom(t *testing.T) {
base := context.Background()
// No identity present.
if u, ok := UserFrom(base); ok || u != "" {
t.Errorf("UserFrom(empty) = %q,%v want \"\",false", u, ok)
}
// Empty user must not attach a value.
if ctx := WithUser(base, ""); ctx != base {
t.Error("WithUser with empty user should return the original context")
}
// Real identity round-trips.
ctx := WithUser(base, "alice")
if u, ok := UserFrom(ctx); !ok || u != "alice" {
t.Errorf("UserFrom = %q,%v want alice,true", u, ok)
}
}