test

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package test provides a shared test harness for gosuki CLI and database tests.

All e2e and integration tests should use this harness to create isolated, reproducible test environments with known seed data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWithDB

func RunWithDB(t testing.TB, fn func(*Harness))

RunWithDB creates a harness, runs the test function, and cleans up. Use this for one-off tests that don't need the harness elsewhere.

Example:

test.RunWithDB(t, func(h *test.Harness) {
    h.SeedBookmarks(test.DefaultSeedSet())
    // ... test logic ...
})

Types

type Harness

type Harness struct {
	DBPath string // Path to temp SQLite database file
	Dir    string // Temp directory (auto-cleaned by testing.T)
	DB     *db.DB // Initialized database handle
}

Harness holds test resources that need cleanup.

func NewHarness

func NewHarness(t testing.TB) *Harness

NewHarness creates a fresh test database with schema initialized.

It uses t.TempDir() for automatic cleanup on test completion and the in-memory-to-disk backup pattern from the existing test suite.

The returned harness has a fully initialized database (schema v4) ready for seeding. Call h.SeedBookmarks() to populate it with test data.

func NewHarnessWithSeed

func NewHarnessWithSeed(t testing.TB, bookmarks []fixtures.SeedBookmark) *Harness

NewHarnessWithSeed is a convenience that creates a harness and seeds it in one call.

func (*Harness) Cleanup

func (h *Harness) Cleanup()

Cleanup closes the database handle. The temp directory is auto-cleaned by testing.T when the test completes.

func (*Harness) SeedAndCount

func (h *Harness) SeedAndCount(bookmarks []fixtures.SeedBookmark) int

SeedAndCount is a convenience method that seeds bookmarks and returns the total row count in gskbookmarks. Useful for verifying insertion.

func (*Harness) SeedBookmarks

func (h *Harness) SeedBookmarks(bookmarks []fixtures.SeedBookmark) int

SeedBookmarks inserts bookmarks into the test database. Returns the number of bookmarks inserted. Panics on SQL errors (tests should not recover from seed failures).

Directories

Path Synopsis
Package fixtures provides seed data and seeding helpers for gosuki tests.
Package fixtures provides seed data and seeding helpers for gosuki tests.

Jump to

Keyboard shortcuts

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