Documentation ¶
Overview ¶
Package context allows integration tests to be written in a fluent, english-like way.
Index ¶
- Constants
- func AfterRun()
- func BeforeRun()
- type Cleaner
- type PMAPIController
- type TestContext
- func (ctx *TestContext) Cleanup() *TestContext
- func (ctx *TestContext) CredentialsFailsOnWrite(shouldFail bool)
- func (ctx *TestContext) DeleteUser(query string, deleteStore bool) (err error)
- func (ctx *TestContext) EnsureAddress(bddUserID, addressOrAddressTestID string) string
- func (ctx *TestContext) EnsureAddressID(bddUserID, addressOrAddressTestID string) string
- func (ctx *TestContext) EventLoopTimeout() time.Duration
- func (ctx *TestContext) EventuallySyncIsFinishedForUsername(username string)
- func (ctx *TestContext) FinishLogin(client pmapi.Client, mailboxPassword []byte) error
- func (ctx *TestContext) GetAPIMessageID(username, bddMessageID string) (string, error)
- func (ctx *TestContext) GetBridge() *bridge.Bridge
- func (ctx *TestContext) GetClientManager() pmapi.Manager
- func (ctx *TestContext) GetDatabaseFilePath(userID string) string
- func (ctx *TestContext) GetIMAPClient(handle string) *mocks.IMAPClient
- func (ctx *TestContext) GetIMAPLastResponse(handle string) *mocks.IMAPResponse
- func (ctx *TestContext) GetLastError() error
- func (ctx *TestContext) GetPMAPIController() PMAPIController
- func (ctx *TestContext) GetSMTPClient(handle string) *mocks.SMTPClient
- func (ctx *TestContext) GetSMTPLastResponse(handle string) *mocks.SMTPResponse
- func (ctx *TestContext) GetStore(username string) (*store.Store, error)
- func (ctx *TestContext) GetStoreAddress(username, addressID string) (*store.Address, error)
- func (ctx *TestContext) GetStoreMailbox(username, addressID, mailboxName string) (*store.Mailbox, error)
- func (ctx *TestContext) GetTestAccount(bddUserID string) *accounts.TestAccount
- func (ctx *TestContext) GetTestAccountWithAddress(bddUserID, bddAddressID string) *accounts.TestAccount
- func (ctx *TestContext) GetTestingError() error
- func (ctx *TestContext) GetTestingT() *bddT
- func (ctx *TestContext) GetUser(username string) (*users.User, error)
- func (ctx *TestContext) GetUserAgent() string
- func (ctx *TestContext) GetUsers() *users.Users
- func (ctx *TestContext) LoginUser(username string, password, mailboxPassword []byte) error
- func (ctx *TestContext) LogoutUser(query string) (err error)
- func (ctx *TestContext) MessagePreparationFinished(username string)
- func (ctx *TestContext) MessagePreparationStarted(username string)
- func (ctx *TestContext) PairMessageID(username, bddMessageID, realMessageID string)
- func (ctx *TestContext) ReorderAddresses(userID, addressA, addressB string)
- func (ctx *TestContext) RestartBridge() error
- func (ctx *TestContext) SetIMAPLastResponse(handle string, resp *mocks.IMAPResponse)
- func (ctx *TestContext) SetLastError(err error)
- func (ctx *TestContext) SetSMTPLastResponse(handle string, resp *mocks.SMTPResponse)
- func (ctx *TestContext) WaitForSync(username string) error
Constants ¶
const ( EnvName = "TEST_ENV" EnvFake = "fake" EnvLive = "live" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cleaner ¶
type Cleaner struct {
// contains filtered or unexported fields
}
Cleaner is a test step that cleans up some stuff post-test.
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) SetDraftBody(username string, messageID string, body 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 LockEvents(username string) UnlockEvents(username string) RemoveUserMessageWithoutEvent(username, messageID string) error RevokeSession(username string) error }
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 (*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) CredentialsFailsOnWrite ¶
func (ctx *TestContext) CredentialsFailsOnWrite(shouldFail bool)
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 ¶
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 ¶
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) 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) GetUser ¶
func (ctx *TestContext) GetUser(username string) (*users.User, error)
GetUser retrieves the bridge user matching the given query string.
func (*TestContext) GetUserAgent ¶
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) MessagePreparationFinished ¶
func (ctx *TestContext) MessagePreparationFinished(username string)
func (*TestContext) MessagePreparationStarted ¶
func (ctx *TestContext) MessagePreparationStarted(username string)
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) WaitForSync ¶
func (ctx *TestContext) WaitForSync(username string) error
WaitForSync waits for sync to be done.