itest

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultModelSource = `package models

import (
	"time"
)

type Product struct {
	ID         string     ` + "`orm:\"pk\"`" + `
	CompanyID  string     ` + "`orm:\"company\"`" + `
	SKU        string     ` + "`orm:\"unique\"`" + `
	Name       string
	PriceCents int64
	DeletedAt  *time.Time ` + "`orm:\"soft_delete\"`" + `
	CreatedAt  time.Time  ` + "`orm:\"created_at\"`" + `
	CreatedBy  string     ` + "`orm:\"created_by\"`" + `
	UpdatedAt  time.Time  ` + "`orm:\"updated_at\"`" + `
	UpdatedBy  string     ` + "`orm:\"updated_by\"`" + `
	DeletedBy  string     ` + "`orm:\"deleted_by\"`" + `
}

type Role struct {
	ID        string    ` + "`orm:\"pk\"`" + `
	Code      string    ` + "`orm:\"unique\"`" + `
	Name      string
	CreatedAt time.Time ` + "`orm:\"created_at\"`" + `
	UpdatedAt time.Time ` + "`orm:\"updated_at\"`" + `
}
`

DefaultModelSource is a compact schema fixture used across integration tests.

Variables

This section is empty.

Functions

func CreateSchema

func CreateSchema(t testing.TB, dsn, schemaName string)

CreateSchema creates a PostgreSQL schema if it does not already exist.

func DropSchema

func DropSchema(t testing.TB, dsn, schemaName string)

DropSchema removes a PostgreSQL schema and its contents.

func RequireDSN

func RequireDSN(t testing.TB) string

RequireDSN returns the PostgreSQL DSN used by the integration tests.

func WithSearchPath

func WithSearchPath(dsn, schemaName string) string

WithSearchPath returns a DSN that targets the given PostgreSQL schema.

Types

type Project

type Project struct {
	BaseDSN       string
	Schema        string
	Root          string
	ModelsDir     string
	MigrationsDir string
	SchemasDir    string
	SnapshotPath  string
	ConfigPath    string
	DSN           string
}

Project owns an isolated PostgreSQL-backed test workspace.

func NewProject

func NewProject(t testing.TB) *Project

NewProject creates a temporary workspace and schema for integration tests.

func (*Project) BuildSchema

func (p *Project) BuildSchema(t testing.TB) *schema.Schema

BuildSchema parses the workspace models into an in-memory schema.

func (*Project) OpenDB

func (p *Project) OpenDB(t testing.TB, obs orm.ObservabilityConfig, preflight bool) *dorm.DB

OpenDB opens a dorm DB using the project DSN.

func (*Project) OpenSQL

func (p *Project) OpenSQL(t testing.TB) *sql.DB

OpenSQL opens a raw *sql.DB against the project schema.

func (*Project) SaveSnapshot

func (p *Project) SaveSnapshot(t testing.TB, s *schema.Schema)

SaveSnapshot persists a schema snapshot for later drift checks.

func (*Project) WriteFile

func (p *Project) WriteFile(t testing.TB, relPath, contents string)

WriteFile writes a project file relative to the workspace root.

func (*Project) WriteJSON

func (p *Project) WriteJSON(t testing.TB, relPath string, value any)

WriteJSON writes a project file as pretty-printed JSON.

Jump to

Keyboard shortcuts

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