context

package
v1.8.11 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: GPL-3.0 Imports: 43 Imported by: 0

Documentation

Overview

Package context allows integration tests to be written in a fluent, english-like way.

Index

Constants

View Source
const (
	EnvName = "TEST_ENV"
	EnvFake = "fake"
	EnvLive = "live"
)

Variables

This section is empty.

Functions

func AfterRun added in v1.8.7

func AfterRun()

AfterRun does necessary cleanup.

func BeforeRun added in v1.8.7

func BeforeRun()

BeforeRun does necessary setup.

Types

type Cleaner

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

Cleaner is a test step that cleans up some stuff post-test.

func (*Cleaner) Execute

func (c *Cleaner) Execute()

Execute runs the cleaner operation.

func (*Cleaner) From

func (c *Cleaner) From() string

From returns the filepath and line number of the place where this cleaner was created.

type PMAPIController

type PMAPIController interface {
	TurnInternetConnectionOff()
	TurnInternetConnectionOn()
	GetAuthClient(username string) pmapi.Client
	AddUser(account *accounts.TestAccount) error
	AddUserLabel(username string, label *pmapi.Label) error
	GetLabelIDs(username string, labelNames []string) ([]string, error)
	AddUserMessage(username string, message *pmapi.Message) (string, error)
	GetMessages(username, labelID string) ([]*pmapi.Message, error)
	ReorderAddresses(user *pmapi.User, addressIDs []string) error
	PrintCalls()
	WasCalled(method, path string, expectedRequest []byte) bool
	WasCalledRegex(methodRegex, pathRegex string, expectedRequest []byte) (bool, error)
	GetCalls(method, path string) [][]byte
}

type TestContext

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

TestContext manages a bridge test (mocked API, bridge instance, IMAP/SMTP servers, setup steps).

func New

func New(app string) *TestContext

New returns a new test TestContext.

func (*TestContext) Cleanup

func (ctx *TestContext) Cleanup() *TestContext

Cleanup runs through all cleanup steps. This can be a deferred call so that it is run even if the test steps failed the test.

func (*TestContext) DeleteUser

func (ctx *TestContext) DeleteUser(query string, deleteStore bool) (err error)

DeleteUser deletes the given user.

func (*TestContext) EnsureAddress

func (ctx *TestContext) EnsureAddress(bddUserID, addressOrAddressTestID string) string

func (*TestContext) EnsureAddressID

func (ctx *TestContext) EnsureAddressID(bddUserID, addressOrAddressTestID string) string

func (*TestContext) EventLoopTimeout

func (ctx *TestContext) EventLoopTimeout() time.Duration

func (*TestContext) EventuallySyncIsFinishedForUsername

func (ctx *TestContext) EventuallySyncIsFinishedForUsername(username string)

EventuallySyncIsFinishedForUsername will wait until sync is finished or deadline is reached see eventuallySyncIsFinished for timing.

func (*TestContext) FinishLogin added in v1.8.7

func (ctx *TestContext) FinishLogin(client pmapi.Client, mailboxPassword []byte) error

FinishLogin prevents authentication if not necessary.

func (*TestContext) GetAPIMessageID

func (ctx *TestContext) GetAPIMessageID(username, bddMessageID string) (string, error)

GetAPIMessageID returns API message ID for given BDD message ID.

func (*TestContext) GetBridge

func (ctx *TestContext) GetBridge() *bridge.Bridge

GetBridge returns bridge instance.

func (*TestContext) GetClientManager added in v1.6.3

func (ctx *TestContext) GetClientManager() pmapi.Manager

GetClientManager returns client manager being used for testing.

func (*TestContext) GetDatabaseFilePath

func (ctx *TestContext) GetDatabaseFilePath(userID string) string

GetDatabaseFilePath returns the file path of the user's store file.

func (*TestContext) GetIMAPClient

func (ctx *TestContext) GetIMAPClient(handle string) *mocks.IMAPClient

GetIMAPClient gets the imap client by name; if it doesn't exist yet it creates it.

func (*TestContext) GetIMAPLastResponse

func (ctx *TestContext) GetIMAPLastResponse(handle string) *mocks.IMAPResponse

GetIMAPLastResponse returns the last IMAP response that was received.

func (*TestContext) GetImportExport

func (ctx *TestContext) GetImportExport() *importexport.ImportExport

GetImportExport returns import-export instance.

func (*TestContext) GetLastError

func (ctx *TestContext) GetLastError() error

GetLastError returns the last error that occurred while executing an action.

func (*TestContext) GetPMAPIController

func (ctx *TestContext) GetPMAPIController() PMAPIController

GetPMAPIController returns API controller, either fake or live.

func (*TestContext) GetSMTPClient

func (ctx *TestContext) GetSMTPClient(handle string) *mocks.SMTPClient

GetSMTPClient gets the smtp client by name; if it doesn't exist yet it creates it.

func (*TestContext) GetSMTPLastResponse

func (ctx *TestContext) GetSMTPLastResponse(handle string) *mocks.SMTPResponse

GetSMTPLastResponse returns the last IMAP response that was received.

func (*TestContext) GetStore

func (ctx *TestContext) GetStore(username string) (*store.Store, error)

GetStore retrieves the store for given username.

func (*TestContext) GetStoreAddress

func (ctx *TestContext) GetStoreAddress(username, addressID string) (*store.Address, error)

GetStoreAddress retrieves the store address for given username and addressID.

func (*TestContext) GetStoreMailbox

func (ctx *TestContext) GetStoreMailbox(username, addressID, mailboxName string) (*store.Mailbox, error)

GetStoreMailbox retrieves the store mailbox for given username, address ID and mailbox name.

func (*TestContext) GetTestAccount

func (ctx *TestContext) GetTestAccount(bddUserID string) *accounts.TestAccount

func (*TestContext) GetTestAccountWithAddress

func (ctx *TestContext) GetTestAccountWithAddress(bddUserID, bddAddressID string) *accounts.TestAccount

func (*TestContext) GetTestingError

func (ctx *TestContext) GetTestingError() error

GetTestingError returns error if test failed by using custom TestingT.

func (*TestContext) GetTestingT

func (ctx *TestContext) GetTestingT() *bddT

GetTestingT returns testing.T compatible struct.

func (*TestContext) GetTransferLocalRootForExport

func (ctx *TestContext) GetTransferLocalRootForExport() string

GetTransferLocalRootForExport creates temporary root for exporting if it not exists yet, and returns its path.

func (*TestContext) GetTransferLocalRootForImport

func (ctx *TestContext) GetTransferLocalRootForImport() string

GetTransferLocalRootForImport creates temporary root for importing if it not exists yet, and returns its path.

func (*TestContext) GetTransferProgress

func (ctx *TestContext) GetTransferProgress() *transfer.Progress

GetTransferProgress returns transfer progress.

func (*TestContext) GetTransferRemoteIMAPServer

func (ctx *TestContext) GetTransferRemoteIMAPServer() *mocks.IMAPServer

GetTransferRemoteIMAPServer creates mocked IMAP server if it not created yet, and returns it.

func (*TestContext) GetTransferSkipEncryptedMessages

func (ctx *TestContext) GetTransferSkipEncryptedMessages() bool

GetTransferSkipEncryptedMessages gets whether encrypted messages will be skipped.

func (*TestContext) GetUser

func (ctx *TestContext) GetUser(username string) (*users.User, error)

GetUser retrieves the bridge user matching the given query string.

func (*TestContext) GetUserAgent added in v1.7.0

func (ctx *TestContext) GetUserAgent() string

GetUserAgent returns the current user agent.

func (*TestContext) GetUsers

func (ctx *TestContext) GetUsers() *users.Users

GetUsers returns users instance.

func (*TestContext) LoginUser

func (ctx *TestContext) LoginUser(username string, password, mailboxPassword []byte) error

LoginUser logs in the user with the given username, password, and mailbox password.

func (*TestContext) LogoutUser

func (ctx *TestContext) LogoutUser(query string) (err error)

LogoutUser logs out the given user.

func (*TestContext) PairMessageID

func (ctx *TestContext) PairMessageID(username, bddMessageID, realMessageID string)

PairMessageID sets pairing between BDD message ID and API message ID.

func (*TestContext) ReorderAddresses

func (ctx *TestContext) ReorderAddresses(userID, addressA, addressB string)

func (*TestContext) RestartBridge

func (ctx *TestContext) RestartBridge() error

RestartBridge closes store for each user and recreates a bridge instance the same way as `withBridgeInstance`. NOTE: This is a very problematic method. It doesn't stop the goroutines doing the event loop and the sync.

These goroutines can continue to run and can cause problems or unexpected behaviour (especially
regarding authorization, because if an auth fails, it will log out the user).
To truly emulate bridge restart, we need a way to immediately stop those goroutines.
I have added a channel that waits up to one second for the event loop to stop, but that isn't great.

func (*TestContext) SetIMAPLastResponse

func (ctx *TestContext) SetIMAPLastResponse(handle string, resp *mocks.IMAPResponse)

SetIMAPLastResponse sets the last IMAP response that was received.

func (*TestContext) SetLastError

func (ctx *TestContext) SetLastError(err error)

SetLastError sets the last error that occurred while executing an action.

func (*TestContext) SetSMTPLastResponse

func (ctx *TestContext) SetSMTPLastResponse(handle string, resp *mocks.SMTPResponse)

SetSMTPLastResponse sets the last SMTP response that was received.

func (*TestContext) SetTransferProgress

func (ctx *TestContext) SetTransferProgress(progress *transfer.Progress)

SetTransferProgress sets transfer progress.

func (*TestContext) SetTransferSkipEncryptedMessages

func (ctx *TestContext) SetTransferSkipEncryptedMessages(value bool)

SetTransferSkipEncryptedMessages sets whether encrypted messages will be skipped.

func (*TestContext) WaitForSync

func (ctx *TestContext) WaitForSync(username string) error

WaitForSync waits for sync to be done.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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