sqlitetest

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sqlitetest provides test doubles for the sqlite package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenBareDB

func OpenBareDB(t *testing.T) sqlite.DB

OpenBareDB creates a temporary SQLite database WITHOUT the PowerSync schema. Use this only for low-level tests (extension loading, watch hooks with custom tables). For most tests, use dbtest.OpenTestDB() which includes the full schema.

Types

type MockDB

type MockDB struct {
	// MessagesImpl is the mock messages implementation.
	MessagesImpl sqlite.Messages

	// ConversationsImpl is the mock conversations implementation.
	ConversationsImpl sqlite.Conversations

	// DatadogAccountStatusesImpl is the mock Datadog account statuses implementation.
	DatadogAccountStatusesImpl sqlite.DatadogAccountStatuses

	// ServiceStatusesImpl is the mock service statuses implementation.
	ServiceStatusesImpl sqlite.ServiceStatuses

	// ServicesImpl is the mock services implementation.
	ServicesImpl sqlite.Services

	// LogEventsImpl is the mock log events implementation.
	LogEventsImpl sqlite.LogEvents

	// LogEventPoliciesImpl is the mock log event policies implementation.
	LogEventPoliciesImpl sqlite.LogEventPolicies

	// SubscriptionImpl is returned by Subscribe.
	SubscriptionImpl *sqlite.Subscription

	// QueryFunc is called by Query.
	QueryFunc func(ctx context.Context, sql string, args ...any) (*sql.Rows, error)

	// QueryRowFunc is called by QueryRow.
	QueryRowFunc func(ctx context.Context, sql string, args ...any) *sql.Row

	// ExecFunc is called by Exec.
	ExecFunc func(ctx context.Context, sql string, args ...any) (sql.Result, error)

	// Closed is set to true when Close is called.
	Closed bool
}

MockDB is a test double for sqlite.DB.

func NewMockDB

func NewMockDB() *MockDB

NewMockDB creates a new MockDB with sensible defaults.

func (*MockDB) Close

func (m *MockDB) Close() error

Close implements sqlite.DB.

func (*MockDB) Conversations

func (m *MockDB) Conversations() sqlite.Conversations

Conversations implements sqlite.DB.

func (*MockDB) DatadogAccountStatuses

func (m *MockDB) DatadogAccountStatuses() sqlite.DatadogAccountStatuses

DatadogAccountStatuses implements sqlite.DB.

func (*MockDB) Exec

func (m *MockDB) Exec(ctx context.Context, sql string, args ...any) (sql.Result, error)

Exec implements sqlite.DB.

func (*MockDB) LogEventPolicies

func (m *MockDB) LogEventPolicies() sqlite.LogEventPolicies

LogEventPolicies implements sqlite.DB.

func (*MockDB) LogEvents

func (m *MockDB) LogEvents() sqlite.LogEvents

LogEvents implements sqlite.DB.

func (*MockDB) Messages

func (m *MockDB) Messages() sqlite.Messages

Messages implements sqlite.DB.

func (*MockDB) PendingUploadCounts

func (m *MockDB) PendingUploadCounts(_ context.Context) (map[sqlite.Table]int64, error)

PendingUploadCounts implements sqlite.DB.

func (*MockDB) Query

func (m *MockDB) Query(ctx context.Context, sql string, args ...any) (*sql.Rows, error)

Query implements sqlite.DB.

func (*MockDB) QueryRow

func (m *MockDB) QueryRow(ctx context.Context, sql string, args ...any) *sql.Row

QueryRow implements sqlite.DB.

func (*MockDB) Raw

func (m *MockDB) Raw() *sql.DB

Raw implements sqlite.DB.

func (*MockDB) ServiceStatuses

func (m *MockDB) ServiceStatuses() sqlite.ServiceStatuses

ServiceStatuses implements sqlite.DB.

func (*MockDB) Services

func (m *MockDB) Services() sqlite.Services

Services implements sqlite.DB.

func (*MockDB) Subscribe

func (m *MockDB) Subscribe() *sqlite.Subscription

Subscribe implements sqlite.DB.

func (*MockDB) WithTx

func (m *MockDB) WithTx(ctx context.Context, fn func(tx *sqlite.Tx) error) error

WithTx implements sqlite.DB.

Jump to

Keyboard shortcuts

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