testkit

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package testkit provides test doubles for authkit consumers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	Users    map[uuid.UUID]gouncer.User
	Sessions map[string]gouncer.Session

	LookupErr        error
	SessionErr       error
	CreateSessionErr error
	DeleteErr        error
	ListUsersErr     error
	CreateUserErr    error
	SetDisabledErr   error
}

Store is an in-memory user and session store encoding the gouncer contract semantics for tests. Set an Err field to force that method to fail.

func NewStore

func NewStore() *Store

NewStore returns an empty Store.

func (*Store) AddUser

func (s *Store) AddUser(tb testing.TB, email, name, password string) gouncer.User

AddUser stores and returns a user built from the given credentials.

func (*Store) CreateSession

func (s *Store) CreateSession(_ context.Context, sess gouncer.Session) error

CreateSession stores sess.

func (*Store) CreateUser

func (s *Store) CreateUser(_ context.Context, u gouncer.User) error

CreateUser stores u, or returns gouncer.ErrEmailTaken for a known email.

func (*Store) DeleteSession

func (s *Store) DeleteSession(_ context.Context, tokenHash []byte) error

DeleteSession removes the session. Removing an absent one is not an error.

func (*Store) ListUsers

func (s *Store) ListUsers(_ context.Context) ([]gouncer.User, error)

ListUsers returns every account ordered by name then id, with password hashes stripped.

func (*Store) SetUserDisabled

func (s *Store) SetUserDisabled(_ context.Context, id uuid.UUID, disabled bool) error

SetUserDisabled updates whether the account may log in, revoking its sessions on disable.

func (*Store) UserByEmail

func (s *Store) UserByEmail(_ context.Context, email string) (gouncer.User, error)

UserByEmail returns the user with the normalized email, or gouncer.ErrUserNotFound.

func (*Store) UserBySession

func (s *Store) UserBySession(_ context.Context, tokenHash []byte, now time.Time) (gouncer.User, error)

UserBySession returns the user owning a live session, or gouncer.ErrSessionNotFound.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL