Documentation
¶
Overview ¶
Package dbtest provides shared database test helpers for seeding and querying test databases. It is designed to be importable from any test package without circular dependency issues (it does not import internal/query).
Index ¶
- func StrPtr(s string) *string
- type ConversationOpts
- type LabelOpts
- type MessageOpts
- type ParticipantOpts
- type SourceOpts
- type TestDB
- func (tdb *TestDB) AddConversation(opts ConversationOpts) int64
- func (tdb *TestDB) AddLabel(opts LabelOpts) int64
- func (tdb *TestDB) AddMessage(opts MessageOpts) int64
- func (tdb *TestDB) AddMessageLabel(messageID, labelID int64)
- func (tdb *TestDB) AddParticipant(opts ParticipantOpts) int64
- func (tdb *TestDB) AddSource(opts SourceOpts) int64
- func (tdb *TestDB) EnableFTS()
- func (tdb *TestDB) LastMessageID() int64
- func (tdb *TestDB) MarkDeletedByID(id int64)
- func (tdb *TestDB) MarkDeletedBySourceID(sourceID string)
- func (tdb *TestDB) MustLookupParticipant(email string) int64
- func (tdb *TestDB) SeedStandardDataSet()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConversationOpts ¶
type ConversationOpts struct {
SourceID int64 // defaults to 1
Title string // defaults to "Test Thread"
}
ConversationOpts configures a conversation to insert.
type LabelOpts ¶
type LabelOpts struct {
SourceID int64 // defaults to 1
SourceLabelID string // defaults to Name
Name string // required
Type string // defaults to "user"
}
LabelOpts configures a label to insert.
type MessageOpts ¶
type MessageOpts struct {
Subject string
SentAt string // e.g. "2024-05-01 10:00:00"
SizeEstimate int
HasAttachments bool
FromID int64 // participant ID for 'from' recipient; 0 = no from
ToIDs []int64 // participant IDs for 'to' recipients
CcIDs []int64 // participant IDs for 'cc' recipients
BccIDs []int64 // participant IDs for 'bcc' recipients
SourceID int64 // defaults to 1 if 0
ConversationID int64 // defaults to 1 if 0
}
MessageOpts configures a message to insert.
type ParticipantOpts ¶
type ParticipantOpts struct {
Email *string // nil = NULL; use StrPtr("x") for a value
DisplayName *string // nil = NULL
Domain string
}
ParticipantOpts configures a participant to insert.
type SourceOpts ¶
type SourceOpts struct {
Identifier string // defaults to "other@gmail.com"
DisplayName string // defaults to "Other Account"
Type string // defaults to "gmail"
}
SourceOpts configures a source to insert.
type TestDB ¶
TestDB wraps a *sql.DB with auto-increment counters and builder helpers for seeding test data.
func NewTestDB ¶
NewTestDB creates an in-memory SQLite database with the production schema loaded. schemaPath is the path to schema.sql (e.g. "../store/schema.sql" from the caller's package). The FTS table is dropped so tests start without it by default.
func (*TestDB) AddConversation ¶
func (tdb *TestDB) AddConversation(opts ConversationOpts) int64
AddConversation inserts a conversation and returns its ID.
func (*TestDB) AddMessage ¶
func (tdb *TestDB) AddMessage(opts MessageOpts) int64
AddMessage inserts a message with its from/to/cc recipients and returns the message ID.
func (*TestDB) AddMessageLabel ¶
AddMessageLabel associates a message with a label.
func (*TestDB) AddParticipant ¶
func (tdb *TestDB) AddParticipant(opts ParticipantOpts) int64
AddParticipant inserts a participant and returns its ID.
func (*TestDB) AddSource ¶
func (tdb *TestDB) AddSource(opts SourceOpts) int64
AddSource inserts a source and returns its ID.
func (*TestDB) EnableFTS ¶
func (tdb *TestDB) EnableFTS()
EnableFTS creates the FTS5 virtual table and populates it from existing test data. Skips the test if FTS5 is not available in this SQLite build.
func (*TestDB) LastMessageID ¶
LastMessageID returns the ID of the most recently added message.
func (*TestDB) MarkDeletedByID ¶
MarkDeletedByID marks a message as deleted by its internal ID.
func (*TestDB) MarkDeletedBySourceID ¶
MarkDeletedBySourceID marks a message as deleted by its source message ID.
func (*TestDB) MustLookupParticipant ¶ added in v0.4.0
MustLookupParticipant returns the ID of the participant with the given email, failing the test if not found.
func (*TestDB) SeedStandardDataSet ¶
func (tdb *TestDB) SeedStandardDataSet()
SeedStandardDataSet inserts the standard test data set: 1 source (test@gmail.com), 3 participants (Alice, Bob, Carol), 1 conversation, 5 messages, 3 labels, and 3 attachments.