apitest

package
v1.22.3 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: 2 Imported by: 0

Documentation

Overview

Package apitest provides test doubles for the powersync/api package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockClientFactory

func NewMockClientFactory(mock *MockClient) func(endpoint string) api.Client

NewMockClientFactory returns a client factory that always returns the given mock.

Types

type MockClient

type MockClient struct {
	// SyncStreamFunc is called when SyncStream is invoked.
	SyncStreamFunc func(ctx context.Context, req *api.SyncStreamRequest, handler api.LineHandler) error

	// GetWriteCheckpointFunc is called when GetWriteCheckpoint is invoked.
	GetWriteCheckpointFunc func(ctx context.Context, clientID string) (string, error)

	// Token is the current token set via SetToken.
	Token string

	// SyncStreamCalls records the number of times SyncStream was called.
	SyncStreamCalls int

	// GetWriteCheckpointCalls records the number of times GetWriteCheckpoint was called.
	GetWriteCheckpointCalls int
}

MockClient is a test double for api.Client.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new MockClient with sensible defaults.

func (*MockClient) GetWriteCheckpoint

func (m *MockClient) GetWriteCheckpoint(ctx context.Context, clientID string) (string, error)

GetWriteCheckpoint implements api.Client.

func (*MockClient) SetToken

func (m *MockClient) SetToken(token string)

SetToken implements api.Client.

func (*MockClient) SyncStream

func (m *MockClient) SyncStream(ctx context.Context, req *api.SyncStreamRequest, handler api.LineHandler) error

SyncStream implements api.Client.

Jump to

Keyboard shortcuts

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