testutil

package
v0.0.0-...-2685407 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestDB

func NewTestDB(t *testing.T) *pgxpool.Pool

NewTestDB creates a new Postgres test container, runs migrations, and returns a connection pool. The container is automatically cleaned up when the test finishes.

func RunMigrations

func RunMigrations(ctx context.Context, pool *pgxpool.Pool) error

RunMigrations reads all migration files and executes them in order. This is exported so it can be used by the E2E test server.

Types

type MemoryBackend

type MemoryBackend struct {
	// contains filtered or unexported fields
}

MemoryBackend is a simple in-memory SMTP backend for testing.

func NewMemoryBackend

func NewMemoryBackend() *MemoryBackend

NewMemoryBackend creates a new in-memory SMTP backend.

func (*MemoryBackend) ClearMessages

func (b *MemoryBackend) ClearMessages()

ClearMessages clears all stored messages.

func (*MemoryBackend) GetMessages

func (b *MemoryBackend) GetMessages() []*memoryMessage

GetMessages returns all received messages.

func (*MemoryBackend) NewSession

func (b *MemoryBackend) NewSession(*smtp.Conn) (smtp.Session, error)

NewSession creates a new SMTP session.

type TestIMAPServer

type TestIMAPServer struct {
	Server  *server.Server
	Address string
	Backend *memory.Backend
	// contains filtered or unexported fields
}

TestIMAPServer represents a test IMAP server instance.

func NewTestIMAPServer

func NewTestIMAPServer(t *testing.T) *TestIMAPServer

NewTestIMAPServer creates a new test IMAP server with an in-memory backend. Returns the server instance and cleanup function. The memory backend creates a default user with username "username" and password "password".

Note: This function is intended for use in test files (requires *testing.T). For E2E tests that don't have a testing context, use NewTestIMAPServerForE2E instead.

func NewTestIMAPServerForE2E

func NewTestIMAPServerForE2E() (*TestIMAPServer, error)

NewTestIMAPServerForE2E creates a new test IMAP server for E2E tests (non-test context). Returns the server instance. The memory backend creates a default user with username "username" and password "password". Uses a fixed port (1143) for E2E tests so Playwright can connect to it. The server includes SPECIAL-USE support for folder role detection.

func (*TestIMAPServer) AddMessage

func (s *TestIMAPServer) AddMessage(t *testing.T, folderName, messageID, subject, from, to string, sentAt time.Time) uint32

AddMessage adds a test message to the specified folder and returns its UID.

func (*TestIMAPServer) AddMessageForE2E

func (s *TestIMAPServer) AddMessageForE2E(folderName, messageID, subject, from, to string, sentAt time.Time) (uint32, error)

AddMessageForE2E adds a test message to the specified folder and returns its UID (non-test context).

func (*TestIMAPServer) Close

func (s *TestIMAPServer) Close()

Close shuts down the test IMAP server.

func (*TestIMAPServer) Connect

func (s *TestIMAPServer) Connect(t *testing.T) (*imapclient.Client, func())

Connect creates a new IMAP client connection to the test server.

func (*TestIMAPServer) ConnectForE2E

func (s *TestIMAPServer) ConnectForE2E() (*imapclient.Client, error)

ConnectForE2E creates a new IMAP client connection to the test server (non-test context).

func (*TestIMAPServer) CreateFolderWithSpecialUse

func (s *TestIMAPServer) CreateFolderWithSpecialUse(folderName string) error

CreateFolderWithSpecialUse creates a folder with SPECIAL-USE attributes (non-test context).

func (*TestIMAPServer) EnsureINBOX

func (s *TestIMAPServer) EnsureINBOX(t *testing.T)

EnsureINBOX ensures the INBOX folder exists for the default user.

func (*TestIMAPServer) EnsureINBOXForE2E

func (s *TestIMAPServer) EnsureINBOXForE2E() error

EnsureINBOXForE2E ensures the INBOX folder exists for the default user (non-test context).

func (*TestIMAPServer) Password

func (s *TestIMAPServer) Password() string

Password returns the default test password.

func (*TestIMAPServer) Username

func (s *TestIMAPServer) Username() string

Username returns the default test username.

type TestSMTPServer

type TestSMTPServer struct {
	Server  *smtp.Server
	Address string
	Backend *MemoryBackend
	// contains filtered or unexported fields
}

TestSMTPServer represents a test SMTP server instance.

func NewTestSMTPServer

func NewTestSMTPServer(t *testing.T) *TestSMTPServer

NewTestSMTPServer creates a new test SMTP server with an in-memory backend. Returns the server instance. The memory backend accepts any username/password combination for testing.

func NewTestSMTPServerForE2E

func NewTestSMTPServerForE2E() (*TestSMTPServer, error)

NewTestSMTPServerForE2E creates a new test SMTP server for E2E tests (non-test context). Returns the server instance. The memory backend accepts any username/password combination. Uses a fixed port (1025) for E2E tests so Playwright can connect to it.

func (*TestSMTPServer) ClearMessages

func (s *TestSMTPServer) ClearMessages()

ClearMessages clears all stored messages.

func (*TestSMTPServer) Close

func (s *TestSMTPServer) Close()

Close shuts down the test SMTP server.

func (*TestSMTPServer) GetMessages

func (s *TestSMTPServer) GetMessages() []*memoryMessage

GetMessages returns all messages received by the server.

func (*TestSMTPServer) Password

func (s *TestSMTPServer) Password() string

Password returns the test password.

func (*TestSMTPServer) Username

func (s *TestSMTPServer) Username() string

Username returns the test username.

Jump to

Keyboard shortcuts

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