tests

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrorMessage

func AssertErrorMessage(t *testing.T, reqCtx *models.RequestContext, status int, message string)

func AssertHasKey

func AssertHasKey(t *testing.T, envelope map[string]any, key string)

func ConcreteRoutePath

func ConcreteRoutePath(path string) string

func DecodeJSONResponse

func DecodeJSONResponse(t *testing.T, w *httptest.ResponseRecorder) map[string]any

func DecodeResponseJSON

func DecodeResponseJSON[T any](t *testing.T, reqCtx *models.RequestContext) T

func GetArray

func GetArray(t *testing.T, envelope map[string]any, key string) []any

func GetMap

func GetMap(t *testing.T, envelope map[string]any, key string) map[string]any

func GetString

func GetString(t *testing.T, envelope map[string]any, key string) string

func JSONRequest

func JSONRequest(t *testing.T, handler http.Handler, method, path string, payload any) *httptest.ResponseRecorder

func MarshalToJSON

func MarshalToJSON(t *testing.T, payload any) []byte

func NewHandlerRequest

func NewHandlerRequest(t *testing.T, method string, path string, body []byte, userID *string) (*http.Request, *httptest.ResponseRecorder, *models.RequestContext)

func NewIntegrationTestDBFromEnv

func NewIntegrationTestDBFromEnv(t *testing.T) (*bun.DB, string)

func NewMySQLIntegrationDB

func NewMySQLIntegrationDB(t *testing.T) *bun.DB

func NewPostgresIntegrationDB

func NewPostgresIntegrationDB(t *testing.T) *bun.DB

func NewSQLiteIntegrationDB

func NewSQLiteIntegrationDB(t *testing.T) *bun.DB

func PtrString

func PtrString(s string) *string

func PtrTime

func PtrTime(t time.Time) *time.Time

func Request

func Request(t *testing.T, handler http.Handler, method, path string, body *bytes.Buffer) *httptest.ResponseRecorder

Types

type BaseTestFixture

type BaseTestFixture struct {
	T                   *testing.T
	DB                  *bun.DB
	Config              *models.Config
	Provider            string
	ServiceRegistry     models.ServiceRegistry
	UserService         coreservices.UserService
	AccountService      coreservices.AccountService
	SessionService      coreservices.SessionService
	VerificationService coreservices.VerificationService
	TokenService        coreservices.TokenService
	// contains filtered or unexported fields
}

func NewBaseTestFixture

func NewBaseTestFixture(t *testing.T, options ...config.ConfigOption) *BaseTestFixture

func (*BaseTestFixture) ResolveID

func (f *BaseTestFixture) ResolveID(id string) string

func (*BaseTestFixture) SeedSession

func (f *BaseTestFixture) SeedSession(sessionID, userID string) string

func (*BaseTestFixture) SeedUser

func (f *BaseTestFixture) SeedUser(id, email string) string

type MockAccountRepository

type MockAccountRepository struct {
	mock.Mock
}

func (*MockAccountRepository) Create

func (m *MockAccountRepository) Create(ctx context.Context, account *models.Account) (*models.Account, error)

func (*MockAccountRepository) Delete

func (m *MockAccountRepository) Delete(ctx context.Context, id string) error

func (*MockAccountRepository) GetAllByUserID

func (m *MockAccountRepository) GetAllByUserID(ctx context.Context, userID string) ([]models.Account, error)

func (*MockAccountRepository) GetByID

func (*MockAccountRepository) GetByProviderAndAccountID

func (m *MockAccountRepository) GetByProviderAndAccountID(ctx context.Context, provider string, accountID string) (*models.Account, error)

func (*MockAccountRepository) GetByUserID

func (m *MockAccountRepository) GetByUserID(ctx context.Context, userID string) (*models.Account, error)

func (*MockAccountRepository) GetByUserIDAndProvider

func (m *MockAccountRepository) GetByUserIDAndProvider(ctx context.Context, userID string, provider string) (*models.Account, error)

func (*MockAccountRepository) Update

func (m *MockAccountRepository) Update(ctx context.Context, account *models.Account) (*models.Account, error)

func (*MockAccountRepository) UpdateFields

func (m *MockAccountRepository) UpdateFields(ctx context.Context, userID string, fields map[string]any) error

func (*MockAccountRepository) WithTx

type MockAccountService

type MockAccountService struct {
	mock.Mock
}

func (*MockAccountService) Create

func (m *MockAccountService) Create(ctx context.Context, userID, accountID, providerID string, password *string) (*models.Account, error)

func (*MockAccountService) CreateOAuth2

func (m *MockAccountService) CreateOAuth2(ctx context.Context, userID, providerAccountID, provider, accessToken string, refreshToken *string, accessTokenExpiresAt, refreshTokenExpiresAt *time.Time, scope *string) (*models.Account, error)

func (*MockAccountService) GetByProviderAndAccountID

func (m *MockAccountService) GetByProviderAndAccountID(ctx context.Context, provider, accountID string) (*models.Account, error)

func (*MockAccountService) GetByUserID

func (m *MockAccountService) GetByUserID(ctx context.Context, userID string) (*models.Account, error)

func (*MockAccountService) GetByUserIDAndProvider

func (m *MockAccountService) GetByUserIDAndProvider(ctx context.Context, userID, provider string) (*models.Account, error)

func (*MockAccountService) Update

func (m *MockAccountService) Update(ctx context.Context, account *models.Account) (*models.Account, error)

func (*MockAccountService) UpdateFields

func (m *MockAccountService) UpdateFields(ctx context.Context, userID string, fields map[string]any) error

type MockEventBus

type MockEventBus struct {
	mock.Mock
}

func (*MockEventBus) Close

func (m *MockEventBus) Close() error

func (*MockEventBus) Publish

func (m *MockEventBus) Publish(ctx context.Context, event models.Event) error

func (*MockEventBus) Subscribe

func (m *MockEventBus) Subscribe(topic string, handler models.EventHandler) (models.SubscriptionID, error)

func (*MockEventBus) Unsubscribe

func (m *MockEventBus) Unsubscribe(topic string, subscriptionID models.SubscriptionID)

type MockLogger

type MockLogger struct{}

func (*MockLogger) Debug

func (m *MockLogger) Debug(msg string, args ...any)

func (*MockLogger) Error

func (m *MockLogger) Error(msg string, args ...any)

func (*MockLogger) Info

func (m *MockLogger) Info(msg string, args ...any)

func (*MockLogger) Panic

func (m *MockLogger) Panic(msg string, args ...any)

func (*MockLogger) Warn

func (m *MockLogger) Warn(msg string, args ...any)

func (*MockLogger) WithField

func (m *MockLogger) WithField(key string, value any) models.Logger

func (*MockLogger) WithFields

func (m *MockLogger) WithFields(fields map[string]any) models.Logger

type MockMailerService

type MockMailerService struct {
	mock.Mock
}

func (*MockMailerService) SendEmail

func (m *MockMailerService) SendEmail(ctx context.Context, to string, subject string, text string, html string) error

type MockPasswordService

type MockPasswordService struct {
	mock.Mock
}

func (*MockPasswordService) Hash

func (m *MockPasswordService) Hash(password string) (string, error)

func (*MockPasswordService) Verify

func (m *MockPasswordService) Verify(password, encoded string) bool

type MockServiceRegistry

type MockServiceRegistry struct {
	mock.Mock
}

func (*MockServiceRegistry) Get

func (m *MockServiceRegistry) Get(name string) any

func (*MockServiceRegistry) Register

func (m *MockServiceRegistry) Register(name string, service any)

type MockSessionRepository

type MockSessionRepository struct {
	mock.Mock
}

func (*MockSessionRepository) Create

func (m *MockSessionRepository) Create(ctx context.Context, session *models.Session) (*models.Session, error)

func (*MockSessionRepository) Delete

func (m *MockSessionRepository) Delete(ctx context.Context, id string) error

func (*MockSessionRepository) DeleteByUserID

func (m *MockSessionRepository) DeleteByUserID(ctx context.Context, userID string) error

func (*MockSessionRepository) DeleteExpired

func (m *MockSessionRepository) DeleteExpired(ctx context.Context) error

func (*MockSessionRepository) DeleteOldestByUserID

func (m *MockSessionRepository) DeleteOldestByUserID(ctx context.Context, userID string, maxCount int) error

func (*MockSessionRepository) GetByID

func (*MockSessionRepository) GetByToken

func (m *MockSessionRepository) GetByToken(ctx context.Context, token string) (*models.Session, error)

func (*MockSessionRepository) GetByUserID

func (m *MockSessionRepository) GetByUserID(ctx context.Context, userID string) (*models.Session, error)

func (*MockSessionRepository) GetDistinctUserIDs

func (m *MockSessionRepository) GetDistinctUserIDs(ctx context.Context) ([]string, error)

func (*MockSessionRepository) Update

func (m *MockSessionRepository) Update(ctx context.Context, session *models.Session) (*models.Session, error)

func (*MockSessionRepository) WithTx

type MockSessionService

type MockSessionService struct {
	mock.Mock
}

func (*MockSessionService) Create

func (m *MockSessionService) Create(ctx context.Context, userID, hashedToken string, ipAddress, userAgent *string, maxAge time.Duration) (*models.Session, error)

func (*MockSessionService) Delete

func (m *MockSessionService) Delete(ctx context.Context, id string) error

func (*MockSessionService) DeleteAllByUserID

func (m *MockSessionService) DeleteAllByUserID(ctx context.Context, userID string) error

func (*MockSessionService) DeleteAllExpired

func (m *MockSessionService) DeleteAllExpired(ctx context.Context) error

func (*MockSessionService) DeleteOldestByUserID

func (m *MockSessionService) DeleteOldestByUserID(ctx context.Context, userID string, maxCount int) error

func (*MockSessionService) GetByID

func (m *MockSessionService) GetByID(ctx context.Context, id string) (*models.Session, error)

func (*MockSessionService) GetByToken

func (m *MockSessionService) GetByToken(ctx context.Context, hashedToken string) (*models.Session, error)

func (*MockSessionService) GetByUserID

func (m *MockSessionService) GetByUserID(ctx context.Context, userID string) (*models.Session, error)

func (*MockSessionService) GetDistinctUserIDs

func (m *MockSessionService) GetDistinctUserIDs(ctx context.Context) ([]string, error)

func (*MockSessionService) Update

func (m *MockSessionService) Update(ctx context.Context, session *models.Session) (*models.Session, error)

type MockTokenRepository

type MockTokenRepository struct {
	mock.Mock
}

func (*MockTokenRepository) Decrypt

func (m *MockTokenRepository) Decrypt(encrypted string) (string, error)

func (*MockTokenRepository) Encrypt

func (m *MockTokenRepository) Encrypt(token string) (string, error)

func (*MockTokenRepository) Generate

func (m *MockTokenRepository) Generate() (string, error)

func (*MockTokenRepository) Hash

func (m *MockTokenRepository) Hash(token string) string

type MockTokenService

type MockTokenService struct {
	mock.Mock
}

func (*MockTokenService) Decrypt

func (m *MockTokenService) Decrypt(encrypted string) (string, error)

func (*MockTokenService) Encrypt

func (m *MockTokenService) Encrypt(token string) (string, error)

func (*MockTokenService) Generate

func (m *MockTokenService) Generate() (string, error)

func (*MockTokenService) Hash

func (m *MockTokenService) Hash(token string) string

type MockUserRepository

type MockUserRepository struct {
	mock.Mock
}

func (*MockUserRepository) Create

func (m *MockUserRepository) Create(ctx context.Context, user *models.User) (*models.User, error)

func (*MockUserRepository) Delete

func (m *MockUserRepository) Delete(ctx context.Context, id string) error

func (*MockUserRepository) GetAll

func (m *MockUserRepository) GetAll(ctx context.Context, cursor *string, limit int) ([]models.User, *string, error)

func (*MockUserRepository) GetByEmail

func (m *MockUserRepository) GetByEmail(ctx context.Context, email string) (*models.User, error)

func (*MockUserRepository) GetByID

func (m *MockUserRepository) GetByID(ctx context.Context, id string) (*models.User, error)

func (*MockUserRepository) Update

func (m *MockUserRepository) Update(ctx context.Context, user *models.User) (*models.User, error)

func (*MockUserRepository) UpdateFields

func (m *MockUserRepository) UpdateFields(ctx context.Context, id string, fields map[string]any) error

func (*MockUserRepository) WithTx

type MockUserService

type MockUserService struct {
	mock.Mock
}

func (*MockUserService) Create

func (m *MockUserService) Create(ctx context.Context, name string, email string, emailVerified bool, image *string, metadata json.RawMessage) (*models.User, error)

func (*MockUserService) Delete

func (m *MockUserService) Delete(ctx context.Context, id string) error

func (*MockUserService) GetAll

func (m *MockUserService) GetAll(ctx context.Context, cursor *string, limit int) ([]models.User, *string, error)

func (*MockUserService) GetByEmail

func (m *MockUserService) GetByEmail(ctx context.Context, email string) (*models.User, error)

func (*MockUserService) GetByID

func (m *MockUserService) GetByID(ctx context.Context, id string) (*models.User, error)

func (*MockUserService) Update

func (m *MockUserService) Update(ctx context.Context, user *models.User) (*models.User, error)

func (*MockUserService) UpdateFields

func (m *MockUserService) UpdateFields(ctx context.Context, id string, fields map[string]any) error

type MockVerificationRepository

type MockVerificationRepository struct {
	mock.Mock
}

func (*MockVerificationRepository) Create

func (*MockVerificationRepository) Delete

func (*MockVerificationRepository) DeleteByUserIDAndType

func (m *MockVerificationRepository) DeleteByUserIDAndType(ctx context.Context, userID string, vType models.VerificationType) error

func (*MockVerificationRepository) DeleteExpired

func (m *MockVerificationRepository) DeleteExpired(ctx context.Context) error

func (*MockVerificationRepository) GetByID

func (*MockVerificationRepository) GetByToken

func (*MockVerificationRepository) WithTx

type MockVerificationService

type MockVerificationService struct {
	mock.Mock
}

func (*MockVerificationService) Create

func (m *MockVerificationService) Create(ctx context.Context, userID string, hashedToken string, vType models.VerificationType, value string, expiry time.Duration) (*models.Verification, error)

func (*MockVerificationService) Delete

func (m *MockVerificationService) Delete(ctx context.Context, id string) error

func (*MockVerificationService) DeleteByUserIDAndType

func (m *MockVerificationService) DeleteByUserIDAndType(ctx context.Context, userID string, vType models.VerificationType) error

func (*MockVerificationService) DeleteExpired

func (m *MockVerificationService) DeleteExpired(ctx context.Context) error

func (*MockVerificationService) GetByToken

func (m *MockVerificationService) GetByToken(ctx context.Context, hashedToken string) (*models.Verification, error)

func (*MockVerificationService) IsExpired

func (m *MockVerificationService) IsExpired(verif *models.Verification) bool

Jump to

Keyboard shortcuts

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