tss-rocks/backend/internal/auth/auth_test.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

27 lines
670 B
Go

package auth
import (
"context"
"testing"
)
func TestUserIDKey(t *testing.T) {
// Test that the UserIDKey constant is defined correctly
if UserIDKey != "user_id" {
t.Errorf("UserIDKey = %v, want %v", UserIDKey, "user_id")
}
// Test context with user ID
ctx := context.WithValue(context.Background(), UserIDKey, "test-user-123")
value := ctx.Value(UserIDKey)
if value != "test-user-123" {
t.Errorf("Context value = %v, want %v", value, "test-user-123")
}
// Test context without user ID
emptyCtx := context.Background()
emptyValue := emptyCtx.Value(UserIDKey)
if emptyValue != nil {
t.Errorf("Empty context value = %v, want nil", emptyValue)
}
}