dbtest

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package dbtest provides minimal DB+model test helpers without depending on auth/capability/share — so it is safe to import from the test files of those packages without creating an import cycle.

If you need a full HTTP server harness (auth wiring, share service, capability probes), use internal/testutil instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestDB

func NewTestDB(t *testing.T) (*sql.DB, db.Store)

NewTestDB opens an in-memory SQLite DB, runs all migrations, and returns the underlying *sql.DB plus a typed Store. Cleanup is registered via t.Cleanup so tests don't have to remember to close.

func ReadJSON

func ReadJSON(t *testing.T, resp *http.Response, out any)

ReadJSON decodes resp.Body into out. Calls t.Fatal on decode failure.

func SeedAdmin

func SeedAdmin(t *testing.T, store db.Store) (string, string)

SeedAdmin creates an admin user with a known password and returns the (email, plaintext password) tuple suitable for downstream login helpers.

func SeedRegularUser

func SeedRegularUser(t *testing.T, store db.Store, email, password string)

SeedRegularUser creates a non-admin user with the supplied credentials.

func SeedUserWithRole

func SeedUserWithRole(t *testing.T, store db.Store, email, password, role string) int64

SeedUserWithRole creates a user with an explicit role and returns the generated user ID. Useful when tests need a specific role beyond the two helpers above.

func TmpFilePath

func TmpFilePath(t *testing.T, name string) string

TmpFilePath returns a path inside t.TempDir() suitable for file create.

Types

This section is empty.

Jump to

Keyboard shortcuts

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