synctest

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTempDB

func CreateTempDB(t *testing.T, dsn string) (string, *sql.DB)

CreateTempDB creates a uniquely-named database for test isolation. Returns the database name and a connection to it. The caller must call DropTempDB in cleanup.

func DropTempDB

func DropTempDB(baseDSN, dbName string)

DropTempDB connects to the base DSN and drops the named database.

func MakePullRequest

func MakePullRequest(clientID string, checkpoint int64, schemaVersion int64, schemaHash string) *synchro.PullRequest

MakePullRequest creates a PullRequest with schema fields for testing.

func MakePushRecord

func MakePushRecord(id, table, operation string, data map[string]any) synchro.PushRecord

MakePushRecord creates a PushRecord for testing.

func MakePushRequest

func MakePushRequest(clientID string, schemaVersion int64, schemaHash string, changes ...synchro.PushRecord) *synchro.PushRequest

MakePushRequest creates a PushRequest with schema fields for testing.

func MakeRegisterRequest

func MakeRegisterRequest(clientID, platform, version string) *synchro.RegisterRequest

MakeRegisterRequest creates a RegisterRequest for testing.

func MustMarshal

func MustMarshal(v any) json.RawMessage

MustMarshal marshals v to JSON or panics.

func NewTestRegistry

func NewTestRegistry() *synchro.Registry

NewTestRegistry creates a minimal Northwind-based registry for testing.

func ReplaceDSNDatabase

func ReplaceDSNDatabase(dsn, newDB string) string

ReplaceDSNDatabase returns a new DSN with the database name replaced.

func SetupTestSchema

func SetupTestSchema(ctx context.Context, db *sql.DB) error

SetupTestSchema creates the application types and tables, then sets REPLICA IDENTITY FULL for WAL logical replication. Idempotent — safe to call on every startup.

func TestDB

func TestDB(t *testing.T) *sql.DB

TestDB creates an isolated temporary database, runs migrations and app DDL, and returns a *sql.DB. It calls t.Skip if TEST_DATABASE_URL is not set. The temporary database is dropped on cleanup.

func TestDBWithAppRole

func TestDBWithAppRole(t *testing.T) (adminDB *sql.DB, appDB *sql.DB)

TestDBWithAppRole creates an isolated temporary database and returns two connections: adminDB (superuser, for DDL/assertions) and appDB (non-superuser, for engine operations under RLS).

PostgreSQL superusers always bypass RLS, so RLS tests must use a non-superuser connection. The function creates the "synchro_app" role (if not exists) and grants it access to all tables in the temp database.

Types

This section is empty.

Jump to

Keyboard shortcuts

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