Files
geo/server/internal/shared/auth/context_test.go
T

37 lines
749 B
Go
Raw Normal View History

package auth
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestWithActorAndFromCtx(t *testing.T) {
actor := Actor{UserID: 1, TenantID: 10, Role: "editor"}
ctx := WithActor(context.Background(), actor)
got, ok := ActorFromCtx(ctx)
assert.True(t, ok)
assert.Equal(t, actor, got)
}
func TestActorFromCtxMissing(t *testing.T) {
_, ok := ActorFromCtx(context.Background())
assert.False(t, ok)
}
func TestMustActorPanics(t *testing.T) {
assert.Panics(t, func() {
MustActor(context.Background())
})
}
func TestMustActorReturns(t *testing.T) {
actor := Actor{UserID: 5, TenantID: 20, Role: "tenant_admin"}
ctx := WithActor(context.Background(), actor)
got := MustActor(ctx)
assert.Equal(t, actor, got)
}