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)
	}
}
