backendtest

package
v1.42.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backendtest is the protocol backend contract (ADR 0037): one suite every backend.Receiver runs, against a fixture that starts the backend and puts mail on, or injects faults into, its server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Message

func Message(id, subject string) []byte

Message is a small message with subject and Message-ID <id>.

func Run

func Run(t *testing.T, start Fixture)

Run runs the contract against the backend start gives.

func RunOnly

func RunOnly(t *testing.T, start Fixture, names ...string)

RunOnly runs only the named parts of the contract, for a backend whose other verbs are still to come.

func RunSender

func RunSender(t *testing.T, start SendFixture)

RunSender runs the sending part of the contract against the backend start gives.

Types

type Delivery

type Delivery struct {
	Rcpts []string // the addresses it goes to
	Raw   []byte   // as the server got it; a backend may add header fields
}

Delivery is one message a sending server accepted.

type Fake added in v1.37.0

type Fake struct {

	// OnSync, when set, runs each Sync in place of the fake's own: it hands
	// commit the pages a test wants stored. It runs without the fake's lock.
	OnSync func(req backend.SyncRequest, commit func(backend.Page) error) (more bool, err error)
	// OnApply, when set, answers each Apply: apply is the fake's own Apply
	// (the server doing op), which it may call or not, and whose answer it may
	// replace (an Unlocated move, a refusal, a lost reply). It runs without the
	// fake's lock.
	OnApply func(op backend.Op, apply func() (backend.Result, error)) (backend.Result, error)
	// contains filtered or unexported fields
}

Fake is a minimal in-memory Server that passes the contract: one folder per name, locations "epoch/n", a folder cursor "epoch/last", IdentityLocation. Tests of local storage script it through OnSync and OnApply.

func NewFake added in v1.37.0

func NewFake() *Fake

NewFake returns an empty Fake.

func (*Fake) Deliver added in v1.37.0

func (s *Fake) Deliver(_ *testing.T, name string, raw []byte)

func (*Fake) Messages added in v1.37.0

func (s *Fake) Messages(name string) map[backend.MessageRef]backend.Flags

Messages is the folder named name as the server has it: each location's flags.

func (*Fake) Receiver added in v1.37.0

func (s *Fake) Receiver(t *testing.T) backend.Receiver

func (*Fake) RejectAuth added in v1.37.0

func (s *Fake) RejectAuth(*testing.T)

func (*Fake) Remove added in v1.37.0

func (s *Fake) Remove(name string, r backend.MessageRef)

Remove deletes the message at r in the folder named name, as another client would.

func (*Fake) Reset added in v1.37.0

func (s *Fake) Reset(_ *testing.T, name string)

func (*Fake) SetFlags added in v1.37.0

func (s *Fake) SetFlags(name string, r backend.MessageRef, fl backend.Flags)

SetFlags sets the flags of the message at r in the folder named name, as another client would.

type Fixture

type Fixture func(t *testing.T) Server

Fixture starts a Server for one test.

type SendFixture

type SendFixture func(t *testing.T) SendServer

SendFixture starts a SendServer for one test.

type SendServer

type SendServer interface {
	// Sender starts a new sending backend on the account.
	Sender(t *testing.T) backend.Sender
	// Accepted is every message the server has accepted, in order.
	Accepted(t *testing.T) []Delivery
	// Refuse makes the server refuse, for good, every message to rcpt.
	Refuse(t *testing.T, rcpt string)
	// LoseVerdict makes the server take the whole next message and then drop
	// the connection without answering.
	LoseVerdict(t *testing.T)
	// RejectAuth makes the server refuse the account's credentials from now on.
	RejectAuth(t *testing.T)
}

SendServer is one fresh account on a fixture's sending server.

type Server

type Server interface {
	// Receiver starts a new backend on the account, closed when t ends.
	Receiver(t *testing.T) backend.Receiver
	// Deliver puts raw into the folder named folder, creating it if need be,
	// as mail arriving. "INBOX" is the inbox.
	Deliver(t *testing.T, folder string, raw []byte)
	// Reset makes the server void every location in the folder named folder:
	// IMAP's UIDVALIDITY changes, JMAP cannot calculate changes. A fixture
	// that cannot calls t.Skip.
	Reset(t *testing.T, folder string)
	// RejectAuth makes the server refuse the account's credentials from now on.
	RejectAuth(t *testing.T)
}

Server is one fresh account on a fixture's server.

Jump to

Keyboard shortcuts

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