mockjmap

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 11 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 mockjmap is an in-process fake JMAP server (httptest) used to test protocol and sync behaviour without a network. Server v1 adds the M2 surface: an EventSource stream with scriptable drops, Email/changes and Mailbox/changes backed by a change journal, and fixture mutators that journal + broadcast so sync-engine tests can drive live reconciliation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Name  string `json:"name,omitempty"`
	Email string `json:"email,omitempty"`
}

Address is a fixture sender/recipient.

type AddressBook

type AddressBook struct {
	ID           string
	Name         string
	SortOrder    uint64
	IsDefault    bool
	IsSubscribed bool
}

AddressBook is a fixture address book.

type Attachment

type Attachment struct {
	BlobID string
	Name   string
	Type   string
	Size   uint64
}

Attachment is a fixture attachment blob reference.

type Contact

type Contact struct {
	ID             string
	AddressBookIDs []string
	Kind           string // "" renders as "individual"
	Given          string
	Surname        string
	Emails         []ContactValue
	Phones         []ContactValue
	Org            string
	Title          string
	Note           string
}

Contact is a fixture contact card. Fixture-friendly fields convert to the JSContact wire shape on set; the stored form is the wire object itself.

type ContactValue

type ContactValue struct {
	Value string
	Label string
}

ContactValue is one labeled entry of a fixture contact (email or phone).

type Email

type Email struct {
	ID            string
	ThreadID      string
	MailboxIDs    []string
	Keywords      map[string]bool
	MessageID     []string
	References    []string
	InReplyTo     []string
	From          []Address
	To            []Address
	Cc            []Address
	Bcc           []Address
	ReplyTo       []Address
	Subject       string
	ReceivedAt    time.Time
	Size          uint64
	HasAttachment bool
	Preview       string
	TextBody      string
	HTMLBody      string
	Attachments   []Attachment
}

Email is a fixture email served by the fake. Bodies are plain strings — the fake does not model MIME structure, only the two part types the client reads (text/plain and text/html) plus attachment metadata.

type Identity

type Identity struct {
	ID    string
	Name  string
	Email string
}

Identity is a fixture sendable identity served by Identity/get.

type Mailbox

type Mailbox struct {
	ID           string
	ParentID     string
	Name         string
	Role         string
	SortOrder    uint64
	TotalEmails  uint64
	UnreadEmails uint64
}

Mailbox is a fixture mailbox served by the fake.

type Server

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

Server is the fake JMAP server.

func New

func New(username, password string, mailboxes []Mailbox) *Server

New starts the server and returns it. Close must be called when done.

func (*Server) BodyGetCalls added in v0.3.3

func (s *Server) BodyGetCalls() int

BodyGetCalls reports how many body-bearing Email/get requests the server has served — a summary fetch does not count. Used to prove a scroll coalesces its body hydration into one request (FR-D4, FR-K4).

func (*Server) Close

func (s *Server) Close()

Close shuts the server down.

func (*Server) CountIn

func (s *Server) CountIn(mailbox string) int

CountIn reports how many fixture emails are in the given mailbox (compose assertions on FR-H4/H6 filing).

func (*Server) CreateEmails

func (s *Server) CreateEmails(emails []Email)

CreateEmails appends fixtures and journals them as created (M2 sync tests drive live arrival this way).

func (*Server) DestroyContacts

func (s *Server) DestroyContacts(ids ...string)

DestroyContacts removes fixture contacts and journals the destruction.

func (*Server) DestroyEmails

func (s *Server) DestroyEmails(ids []string)

DestroyEmails removes fixtures and journals them as destroyed.

func (*Server) DisableContacts

func (s *Server) DisableContacts()

DisableContacts drops the contacts capability from the session (FR-L6 gating tests). The API answers unknownMethod for contacts calls.

func (*Server) DropStreams

func (s *Server) DropStreams()

DropStreams terminates every connected EventSource stream (kill-the-push tests, FR-B3).

func (*Server) FailAPI added in v0.3.2

func (s *Server) FailAPI(n int)

FailAPI makes the next n API POSTs answer HTTP 500 (transient-failure tests: the client's retry path).

func (*Server) FailStreams

func (s *Server) FailStreams(n int)

FailStreams makes the next n EventSource connects fail (FR-B3 tests).

func (*Server) Notify

func (s *Server) Notify()

Notify broadcasts a StateChange event to every connected stream. Types whose state has not moved since the last Notify are omitted.

func (*Server) SetAddressBooks

func (s *Server) SetAddressBooks(books []AddressBook)

SetAddressBooks replaces the address-book fixtures and journals the change (external-edit tests).

func (*Server) SetBlob

func (s *Server) SetBlob(id string, data []byte)

SetBlob registers blob bytes for the download endpoint. Fixture attachments reference the registered blob id.

func (*Server) SetCalls

func (s *Server) SetCalls() int

SetCalls reports how many Email/set requests the server has served (batching assertions, FR-K4).

func (*Server) SetCannotCalculateChanges

func (s *Server) SetCannotCalculateChanges(v bool)

SetCannotCalculateChanges makes /changes answer cannotCalculateChanges (PLAN §4.1 case 2 tests).

func (*Server) SetContacts

func (s *Server) SetContacts(contacts []Contact)

SetContacts replaces the contact fixtures and journals every id as updated (external-edit tests).

func (*Server) SetEmails

func (s *Server) SetEmails(emails []Email)

SetEmails replaces the email fixtures and journals the change: ids present in both sets count as updated, ids only in the old set count as destroyed.

func (*Server) SetIdentities

func (s *Server) SetIdentities(ids []Identity)

SetIdentities replaces the identity fixtures. With none set the fake serves a single identity derived from the login, which is what a real account looks like (FR-H1).

func (*Server) SetMailboxes

func (s *Server) SetMailboxes(mailboxes []Mailbox)

SetMailboxes replaces the mailbox fixtures and journals the change.

func (*Server) SetSyntheticMailbox

func (s *Server) SetSyntheticMailbox(sm SyntheticMailbox)

SetSyntheticMailbox sets (or clears with Count 0) the virtual mailbox. Synthetic content is generated on demand, so the journal records a bare version bump: /changes reports a new state with no per-id detail.

func (*Server) StreamCount

func (s *Server) StreamCount() int

StreamCount reports connected EventSource streams (test assertions).

func (*Server) SubjectIn

func (s *Server) SubjectIn(mailbox, subject string) int

SubjectIn reports how many emails in mailbox carry exactly subject.

func (*Server) URL

func (s *Server) URL() string

URL is the server base URL, suitable as jmapclient's ServerURL.

func (*Server) UpdateEmails

func (s *Server) UpdateEmails(ids []string, fn func(*Email))

UpdateEmails mutates the named fixtures in place and journals them as updated (flag flips, subject edits, moves). Unknown ids are ignored.

type SyntheticMailbox

type SyntheticMailbox struct {
	MailboxID string
	Prefix    string
	Count     int
}

SyntheticMailbox declares a virtual mailbox with Count generated messages: ids "<prefix>-<index>", deterministically derived content, and receivedAt descending in index order. Nothing is materialised until a query or get touches it, so 10k+ message fixtures stay cheap (M1 soak).

Jump to

Keyboard shortcuts

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