61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetUserID_Empty(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.Background()
|
|
if id := GetUserID(ctx); id != "" {
|
|
t.Errorf("expected empty user ID, got %q", id)
|
|
}
|
|
}
|
|
|
|
func TestGetUserID_Set(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.WithValue(context.Background(), UserIDKey, "abc-123")
|
|
if id := GetUserID(ctx); id != "abc-123" {
|
|
t.Errorf("expected abc-123, got %q", id)
|
|
}
|
|
}
|
|
|
|
func TestGetUserEmail_Empty(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.Background()
|
|
if email := GetUserEmail(ctx); email != "" {
|
|
t.Errorf("expected empty email, got %q", email)
|
|
}
|
|
}
|
|
|
|
func TestGetUserEmail_Set(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.WithValue(context.Background(), UserEmailKey, "test@example.com")
|
|
if email := GetUserEmail(ctx); email != "test@example.com" {
|
|
t.Errorf("expected test@example.com, got %q", email)
|
|
}
|
|
}
|
|
|
|
func TestGetUserTier_Default(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.Background()
|
|
if tier := GetUserTier(ctx); tier != "free" {
|
|
t.Errorf("expected default tier 'free', got %q", tier)
|
|
}
|
|
}
|
|
|
|
func TestGetUserTier_Set(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.WithValue(context.Background(), UserTierKey, "pro")
|
|
if tier := GetUserTier(ctx); tier != "pro" {
|
|
t.Errorf("expected 'pro', got %q", tier)
|
|
}
|
|
}
|