backendtests

package module
v0.0.0-...-b31cc65 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: MIT Imports: 21 Imported by: 0

README

go-imap-backend-tests

Blackbox tests for go-imap backends.

The main intention of suite is to test for basic RFC 3501 conformance. Tests are developed in parallel with go-imap-sql so they reflect its conformance.

Tests

  • IMAPUserDB interface tests
  • Tests for mailbox management commands
  • Tests for SEARCH and FETCH commands (for UID versions too) (ListMessages, SearchMessages)
  • Tests for COPY/UID COPY commands (CopyMessages)
  • Tests for STATUS command (Status)
  • Tests for EXPUNGE command (Expunge)
  • Tests for UPDATE command (SetMessagesFlags)
  • Tests for unilateral updates (optional, backend.Updater interface)
  • Test for UID monotonic increase
  • Test for UIDVALIDITY/UIDNEXT change on mailbox rename
  • APPENDLIMIT extension tests (optional, see [appendlimit.go][appendlimit.go] for interfaces)
  • CHILDREN extension tests (optional, see [children/server.go][children/server.go] for interfaces)
  • MOVE extension tests (optional) (MoveMessages)

Blacklist/whitelist tests

You can disable some tests by setting Whitelist or Blacklist slices before calling RunTests.

If Whitelistis not nil, only tests that have name starting with any listed string will be run.

If Blacklistis not nil, tests that have name starting with any listed string will not be run. Blacklist is still checked if Whitelistis set.

Excluded tests will be skipped using testing/T.SkipNow function.

For strings, use full name of test, as printed by go test -v, but unescaped.

Incomplete RFC 3501 conformance

As this suite reflects state of go-imap-sql implementation, it may not test for all requirements of IMAP specification. There are known ignored cases:

  • /NoSelect attribute and removal of mailboxes with children

How to use

Tested backend must implement IMAPUsersDB interface.

Just call testsuite.RunTests(t, newBackend, closeBackend) from your backend (or backend_test) package. Each invocation of newBackend callback should provide clean instance of backend (e.g. with empty storage, etc). closeBackend will be called for backend after usage. New instance is created for each test.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserAlreadyExists = errors.New("imap: user already exists")
	ErrUserDoesntExists  = errors.New("imap: user doesn't exists")
)
View Source
var Blacklist []string
View Source
var Whitelist []string

Functions

func Backend_AppendLimit

func Backend_AppendLimit(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_AppendLimit

func Mailbox_AppendLimit(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_Children

func Mailbox_Children(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_CopyMessages

func Mailbox_CopyMessages(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_CreateMessage

func Mailbox_CreateMessage(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_Expunge

func Mailbox_Expunge(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_ExpungeUpdate

func Mailbox_ExpungeUpdate(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_Info

func Mailbox_Info(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_ListMessages

func Mailbox_ListMessages(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_ListMessages_Body

func Mailbox_ListMessages_Body(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_ListMessages_BodyPeek

func Mailbox_ListMessages_BodyPeek(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_ListMessages_Meta

func Mailbox_ListMessages_Meta(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_ListMessages_Multi

func Mailbox_ListMessages_Multi(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_MessageUpdate

func Mailbox_MessageUpdate(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_MonotonicUid

func Mailbox_MonotonicUid(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_MoveMessages

func Mailbox_MoveMessages(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_SearchMessages

func Mailbox_SearchMessages(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_SetMessageFlags

func Mailbox_SetMessageFlags(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_SetSubscribed

func Mailbox_SetSubscribed(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_Status

func Mailbox_Status(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_StatusUpdate

func Mailbox_StatusUpdate(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_StatusUpdate_Copy

func Mailbox_StatusUpdate_Copy(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_StatusUpdate_Move

func Mailbox_StatusUpdate_Move(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func Mailbox_UidValidity_On_Rename

func Mailbox_UidValidity_On_Rename(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func RunTests

func RunTests(t *testing.T, newBackend NewBackFunc, closeBackend CloseBackFunc)

RunTests runs all tests against backend created using passed callback functions.

func TestInit

func TestInit(t *testing.T, newBackend NewBackFunc, closeBackend CloseBackFunc)

func UserDB_CreateUser

func UserDB_CreateUser(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func UserDB_DeleteUser

func UserDB_DeleteUser(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func UserDB_Login

func UserDB_Login(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func UserDB_SetPassword

func UserDB_SetPassword(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_AppendLimit

func User_AppendLimit(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_CreateMailbox

func User_CreateMailbox(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_CreateMailbox_Parents

func User_CreateMailbox_Parents(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_DeleteMailbox

func User_DeleteMailbox(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_DeleteMailbox_Parents

func User_DeleteMailbox_Parents(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_ListMailboxes

func User_ListMailboxes(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_RenameMailbox

func User_RenameMailbox(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_RenameMailbox_Childrens

func User_RenameMailbox_Childrens(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_RenameMailbox_INBOX

func User_RenameMailbox_INBOX(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

func User_Username

func User_Username(t *testing.T, newBack NewBackFunc, closeBack CloseBackFunc)

Types

type AppendLimitBackend

type AppendLimitBackend interface {
	appendlimit.Backend

	// SetMessageLimit sets new value for limit.
	// nil pointer means no limit.
	SetMessageLimit(val *uint32) error
}

AppendLimitBackend is extension for main backend interface (backend.Backend) which allows to set append limit value for testing and administration purposes.

type AppendLimitMbox

type AppendLimitMbox interface {
	CreateMessageLimit() *uint32

	// SetMessageLimit sets new value for limit.
	// nil pointer means no limit.
	SetMessageLimit(val *uint32) error
}

AppendLimitMbox is extension for backend.Mailbox interface which allows to set append limit value for testing and administration purposes.

type AppendLimitUser

type AppendLimitUser interface {
	appendlimit.User

	// SetMessageLimit sets new value for limit.
	// nil pointer means no limit.
	SetMessageLimit(val *uint32) error
}

AppendLimitUser is extension for backend.User interface which allows to set append limit value for testing and administration purposes.

type Backend

type Backend interface {
	backend.Backend
	IMAPUsersDB
}

type CloseBackFunc

type CloseBackFunc func(Backend)

CloseBackFunc should clean up Backend object after testing.

Most importantly, it should ensure that all persistent data is removed so next test will get clean state.

type IMAPUsersDB

type IMAPUsersDB interface {
	UsersDB

	// GetUser is same as Backend.Login but doesn't
	// performs any authentication.
	GetUser(username string) (backend.User, error)
}

type NewBackFunc

type NewBackFunc func() Backend

NewBackFunc should create new Backend object configured for testing.

It should ensure that backend object created with each call gets a clean empty state.

type UsersDB

type UsersDB interface {
	// CreateUser creates new user with specified username.
	//
	// No mailboxes are created for new user, even INBOX.  This should be done
	// manually using CreateMailbox.
	//
	// It is error to create user which already exists.  ErrUserAlreadyExists
	// will be returned in this case.
	//
	// To backend implementers: You need to only return error with same message
	// for tests to work correctly.
	CreateUser(username, password string) error

	// DeleteUser deletes user account from backend storage, along with all
	// mailboxes and messages.
	//
	// It is error to delete user which doesn't exists.  ErrUserDoesntExists
	// will be returned in this case.
	//
	// To backend implementers: You need to only return error with same message
	// for tests to work correctly.
	DeleteUser(username string) error

	// SetUserPassword updates password of existsing user.
	//
	// It is error to update user which doesn't exists.  ErrUserDoesntExists
	// will be returned in this case.
	//
	// To backend implementers: You need to only return error with same message
	// for tests to work correctly.
	SetUserPassword(username, newPassword string) error
}

UsersDB is additional backend interface that allows external code to perform administrative actions on backend's storage related to users.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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