powersynctest

package
v1.22.1 Latest Latest
Warning

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

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

Documentation

Overview

Package powersynctest provides test utilities for the powersync package.

For database test helpers, use powersync/db/dbtest. For mock API clients, use powersync/api/apitest.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSyncerWithMockClient

func NewSyncerWithMockClient(endpoint string, tokenRefresher powersync.TokenRefresher, mock *apitest.MockClient) powersync.Syncer

NewSyncerWithMockClient creates a Syncer with a mock client for testing.

Types

type MockSyncer

type MockSyncer struct {
	StartFunc                 func(ctx context.Context, db sqlite.DB, accountID string, onFirstSync func()) error
	StopFunc                  func()
	StateFunc                 func() powersync.State
	IsReadyFunc               func() bool
	NotifyUploadCompletedFunc func(ctx context.Context) error
}

MockSyncer is a test double for powersync.Syncer.

func NewMockSyncer

func NewMockSyncer() *MockSyncer

NewMockSyncer creates a MockSyncer with sensible defaults.

func (*MockSyncer) IsReady

func (m *MockSyncer) IsReady() bool

func (*MockSyncer) NotifyUploadCompleted added in v1.22.1

func (m *MockSyncer) NotifyUploadCompleted(ctx context.Context) error

func (*MockSyncer) Start

func (m *MockSyncer) Start(ctx context.Context, db sqlite.DB, accountID string, onFirstSync func()) error

func (*MockSyncer) State

func (m *MockSyncer) State() powersync.State

func (*MockSyncer) Stop

func (m *MockSyncer) Stop()

type MockTokenRefresher

type MockTokenRefresher struct {
	// GetAccessTokenFunc is called when GetAccessToken is invoked.
	GetAccessTokenFunc func(ctx context.Context) (string, error)

	// ForceRefreshAccessTokenFunc is called when ForceRefreshAccessToken is invoked.
	ForceRefreshAccessTokenFunc func(ctx context.Context) (string, error)

	// Calls records the number of times GetAccessToken was called.
	Calls int

	// ForceRefreshCalls records the number of times ForceRefreshAccessToken was called.
	ForceRefreshCalls int
}

MockTokenRefresher is a test double for powersync.TokenRefresher.

func NewMockTokenRefresher

func NewMockTokenRefresher(token string) *MockTokenRefresher

NewMockTokenRefresher creates a MockTokenRefresher that returns the given token.

func (*MockTokenRefresher) ForceRefreshAccessToken added in v1.16.0

func (m *MockTokenRefresher) ForceRefreshAccessToken(ctx context.Context) (string, error)

ForceRefreshAccessToken implements powersync.TokenRefresher.

func (*MockTokenRefresher) GetAccessToken

func (m *MockTokenRefresher) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken implements powersync.TokenRefresher.

Jump to

Keyboard shortcuts

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