testfixture

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package testfixture owns disk scenarios and their isolated repositories and caches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Case

type Case struct {
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Setup       []operation       `json:"setup"`
	Directory   string            `json:"directory,omitempty"`
	Env         map[string]string `json:"env"`
	Cache       replayCache       `json:"cache"`
	Steps       []Step            `json:"steps"`
}

Case requires an explicit cache policy and ordered edits or invocations.

type Fixture

type Fixture struct {
	Plan      Case
	Repo      string
	Inputs    string
	Home      string
	Responses []Response
	// contains filtered or unexported fields
}

Fixture isolates materialized state from the immutable disk scenario.

func Materialize

func Materialize(tb testing.TB, scenarioName, variant string) *Fixture

Materialize locates scenarios independently of the current working directory.

func (*Fixture) Cache

func (f *Fixture) Cache(tb testing.TB, inv *Invocation) string

Cache resets only the cache selected by the invocation.

func (*Fixture) CachePath

func (f *Fixture) CachePath(name string) string

CachePath must not reset or create caches while resolving expectations.

func (*Fixture) Edit

func (f *Fixture) Edit(tb testing.TB, step Step)

Edit permits only the operation declared by an edit step.

func (*Fixture) Load

func (f *Fixture) Load(endpoint *transport.Endpoint) (storer.Storer, error)

Load permits Git transport only to a declared repository's origin URL.

func (*Fixture) Read

func (f *Fixture) Read(tb testing.TB, path, cache string) string

Read rejects paths outside the disk scenario.

func (*Fixture) Resolve

func (f *Fixture) Resolve(tb testing.TB, value, cache string) string

Resolve rejects commit tokens that the scenario does not declare.

func (*Fixture) Restore

func (f *Fixture) Restore(tb testing.TB)

Restore preserves caches only when the case explicitly requests reuse.

type Invocation

type Invocation struct {
	Argv      []string          `json:"argv"`
	Transport []Response        `json:"transport,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
	Cache     cacheSelection    `json:"cache"`
	Expect    expectation       `json:"expect"`
}

Invocation requires complete output and exit-code expectations.

type Response

type Response struct {
	Host    string            `json:"host"`
	Method  string            `json:"method"`
	Path    string            `json:"path"`
	Status  int               `json:"status,omitempty"`
	Error   string            `json:"error,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    string            `json:"body,omitempty"`
}

Response limits fixture transport to a declared host, method, and path.

type Step

type Step struct {
	ID     string      `json:"id"`
	Edit   *operation  `json:"edit,omitempty"`
	Invoke *Invocation `json:"invoke,omitempty"`
}

Step permits exactly one edit or invocation.

Jump to

Keyboard shortcuts

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