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 ¶
- type Address
- type AddressBook
- type Attachment
- type Contact
- type ContactValue
- type Email
- type Identity
- type Mailbox
- type Server
- func (s *Server) BodyGetCalls() int
- func (s *Server) Close()
- func (s *Server) CountIn(mailbox string) int
- func (s *Server) CreateEmails(emails []Email)
- func (s *Server) DestroyContacts(ids ...string)
- func (s *Server) DestroyEmails(ids []string)
- func (s *Server) DisableContacts()
- func (s *Server) DropStreams()
- func (s *Server) FailAPI(n int)
- func (s *Server) FailStreams(n int)
- func (s *Server) Notify()
- func (s *Server) SetAddressBooks(books []AddressBook)
- func (s *Server) SetBlob(id string, data []byte)
- func (s *Server) SetCalls() int
- func (s *Server) SetCannotCalculateChanges(v bool)
- func (s *Server) SetContacts(contacts []Contact)
- func (s *Server) SetEmails(emails []Email)
- func (s *Server) SetIdentities(ids []Identity)
- func (s *Server) SetMailboxes(mailboxes []Mailbox)
- func (s *Server) SetSyntheticMailbox(sm SyntheticMailbox)
- func (s *Server) StreamCount() int
- func (s *Server) SubjectIn(mailbox, subject string) int
- func (s *Server) URL() string
- func (s *Server) UpdateEmails(ids []string, fn func(*Email))
- type SyntheticMailbox
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressBook ¶
AddressBook is a fixture address book.
type Attachment ¶
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 ¶
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 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 (*Server) BodyGetCalls ¶ added in v0.3.3
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) CountIn ¶
CountIn reports how many fixture emails are in the given mailbox (compose assertions on FR-H4/H6 filing).
func (*Server) CreateEmails ¶
CreateEmails appends fixtures and journals them as created (M2 sync tests drive live arrival this way).
func (*Server) DestroyContacts ¶
DestroyContacts removes fixture contacts and journals the destruction.
func (*Server) DestroyEmails ¶
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
FailAPI makes the next n API POSTs answer HTTP 500 (transient-failure tests: the client's retry path).
func (*Server) FailStreams ¶
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 ¶
SetBlob registers blob bytes for the download endpoint. Fixture attachments reference the registered blob id.
func (*Server) SetCalls ¶
SetCalls reports how many Email/set requests the server has served (batching assertions, FR-K4).
func (*Server) SetCannotCalculateChanges ¶
SetCannotCalculateChanges makes /changes answer cannotCalculateChanges (PLAN §4.1 case 2 tests).
func (*Server) SetContacts ¶
SetContacts replaces the contact fixtures and journals every id as updated (external-edit tests).
func (*Server) SetEmails ¶
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 ¶
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 ¶
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 ¶
StreamCount reports connected EventSource streams (test assertions).
func (*Server) UpdateEmails ¶
UpdateEmails mutates the named fixtures in place and journals them as updated (flag flips, subject edits, moves). Unknown ids are ignored.
type SyntheticMailbox ¶
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).