storetest

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package storetest provides a StoreFixture and helpers for tests that exercise the Store layer through its public API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fixture

type Fixture struct {
	T      *testing.T
	Store  *store.Store
	Source *store.Source
	ConvID int64
	// contains filtered or unexported fields
}

Fixture holds common test state for store-level tests.

func New

func New(t *testing.T) *Fixture

New creates a Fixture with a fresh test database, one source ("test@example.com") and one default conversation.

func (*Fixture) AssertActiveSync

func (f *Fixture) AssertActiveSync(wantID int64, wantStatus string)

AssertActiveSync asserts there is an active sync with the given ID and status.

func (*Fixture) AssertLabelCount

func (f *Fixture) AssertLabelCount(msgID int64, want int)

AssertLabelCount asserts the number of labels attached to a message.

func (*Fixture) AssertMessageDeleted

func (f *Fixture) AssertMessageDeleted(msgID int64)

AssertMessageDeleted asserts that a message has been marked as deleted.

func (*Fixture) AssertMessageNotDeleted

func (f *Fixture) AssertMessageNotDeleted(msgID int64)

AssertMessageNotDeleted asserts that a message has NOT been marked as deleted.

func (*Fixture) AssertNoActiveSync

func (f *Fixture) AssertNoActiveSync()

AssertNoActiveSync asserts there is no active sync for the fixture's source.

func (*Fixture) AssertRecipientCount

func (f *Fixture) AssertRecipientCount(msgID int64, typ string, want int)

AssertRecipientCount asserts the number of recipients of a given type for a message.

func (*Fixture) CreateMessage

func (f *Fixture) CreateMessage(sourceMessageID string) int64

CreateMessage inserts a minimal message and returns its internal ID.

func (*Fixture) CreateMessages

func (f *Fixture) CreateMessages(count int) []int64

CreateMessages inserts count messages with IDs "msg-0" .. "msg-(count-1)".

func (*Fixture) EnsureLabels

func (f *Fixture) EnsureLabels(labels map[string]string, typ string) map[string]int64

EnsureLabels creates labels and returns a map of sourceLabelID → internal ID.

func (*Fixture) EnsureParticipant

func (f *Fixture) EnsureParticipant(email, name, domain string) int64

EnsureParticipant creates or gets a participant and returns its ID.

func (*Fixture) GetMessageBody added in v0.4.0

func (f *Fixture) GetMessageBody(msgID int64) (sql.NullString, sql.NullString)

GetMessageBody returns the body_text and body_html for a message.

func (*Fixture) GetMessageFields added in v0.4.0

func (f *Fixture) GetMessageFields(msgID int64) MessageFields

GetMessageFields returns selected fields of a message by ID.

func (*Fixture) GetSingleLabelID added in v0.4.0

func (f *Fixture) GetSingleLabelID(msgID int64) int64

GetSingleLabelID returns the label_id for a message that should have exactly one label.

func (*Fixture) GetSingleRecipientID added in v0.4.0

func (f *Fixture) GetSingleRecipientID(msgID int64, typ string) int64

GetSingleRecipientID returns the participant_id for a message+type that should have exactly one recipient.

func (*Fixture) GetSyncRun added in v0.4.0

func (f *Fixture) GetSyncRun(syncID int64) (status, errorMsg string)

GetSyncRun returns the status and error_message for a sync run by ID.

func (*Fixture) NewMessage

func (f *Fixture) NewMessage() *MessageBuilder

NewMessage creates a builder using the fixture's per-test counter for deterministic SourceMessageID values (fixture-msg-1, fixture-msg-2, ...). Uses a distinct prefix from the package-level NewMessage to avoid collisions.

func (*Fixture) StartSync

func (f *Fixture) StartSync() int64

StartSync starts a sync run and returns its ID.

type MessageBuilder

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

MessageBuilder provides a fluent API for constructing store.Message values.

func NewMessage

func NewMessage(sourceID, convID int64) *MessageBuilder

NewMessage creates a builder with sensible defaults. NewMessage creates a builder with sensible defaults. It uses a global counter to generate unique SourceMessageID values; prefer Fixture.NewMessage for per-test deterministic IDs.

func (*MessageBuilder) Build

func (b *MessageBuilder) Build() *store.Message

Build returns the constructed Message.

func (*MessageBuilder) Create

func (b *MessageBuilder) Create(t *testing.T, st *store.Store) int64

Create inserts the message into the store and returns its internal ID.

func (*MessageBuilder) WithAttachmentCount added in v0.4.0

func (b *MessageBuilder) WithAttachmentCount(count int) *MessageBuilder

WithAttachmentCount sets the attachment count and HasAttachments flag.

func (*MessageBuilder) WithInternalDate

func (b *MessageBuilder) WithInternalDate(t time.Time) *MessageBuilder

func (*MessageBuilder) WithIsFromMe

func (b *MessageBuilder) WithIsFromMe(v bool) *MessageBuilder

func (*MessageBuilder) WithReceivedAt

func (b *MessageBuilder) WithReceivedAt(t time.Time) *MessageBuilder

func (*MessageBuilder) WithSentAt

func (b *MessageBuilder) WithSentAt(t time.Time) *MessageBuilder

func (*MessageBuilder) WithSize

func (b *MessageBuilder) WithSize(n int64) *MessageBuilder

func (*MessageBuilder) WithSnippet

func (b *MessageBuilder) WithSnippet(s string) *MessageBuilder

func (*MessageBuilder) WithSourceMessageID

func (b *MessageBuilder) WithSourceMessageID(id string) *MessageBuilder

func (*MessageBuilder) WithSubject

func (b *MessageBuilder) WithSubject(s string) *MessageBuilder

type MessageFields added in v0.4.0

type MessageFields struct {
	Subject        string
	Snippet        string
	HasAttachments bool
}

MessageFields holds a subset of message columns for test verification.

Jump to

Keyboard shortcuts

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