formattest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package formattest is the contract suite for package formats (decision 0032). Every format runs Run with a fixture that builds packages of its type, and one set of scenarios proves, on the in-memory, SQLite and PostgreSQL stores, that its package index (decision 0018) stays right on every write path the item service offers: deploy, overwrite, delete, copy, move, restore from the trash can, property changes and a remote repository's cache.

"Right" has two halves. The fixture says which versions a scenario leaves and which files each links. And the item tree is the source of truth, so the index the hooks kept must be the one the format's reindex reads from the tree: a reindex over it changes nothing, and a reindex from an empty index rebuilds it, every version's metadata included. A format that indexes nothing must leave the index empty.

Two options of the fixture cover what P8's formats add (decision 0032, "Verification"):

  • Format.RepoWork lists the kinds of derived work a format keys by repository, such as Helm's index.yaml (decision 0039). Every write that changes a repository's versions must leave exactly one item of each, keyed by the repository's key, however many packages it touched: after a deploy, an overwrite, a copy (its target), a move (both repositories), a delete and a restore. Format.Work keeps the kinds keyed by package, as npm's, Go's and Maven's are.
  • File.SidecarOf marks a file as a sidecar its format keeps with its owner (format.SidecarKeeper), such as a Helm chart's .prov. A sidecar is never a version file. It follows its owner through a delete, a copy, a move and a trash restore. On its own it is an ordinary file that may arrive before its owner. A format that records its sidecars in a version's metadata has that compared after a reindex from empty too.

The suite drives the item service, whose entry points every API calls: the properties API and AQL properties.update call Service.Annotate, which internal/server's TestAccPropertyWritesReachTheFormat holds them to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, f Format)

Run runs every scenario of the contract for f on every backend, each on a fresh store.

Types

type Backend

type Backend struct {
	Name string
	Open func(t *testing.T) store.Store
}

Backend opens a fresh, empty store for one scenario.

func Backends

func Backends() []Backend

Backends are the stores the suite runs on: the in-memory reference, SQLite on disk and PostgreSQL, which skips where Docker cannot run Linux containers.

type File

type File struct {
	// Path is repository-relative.
	Path string
	Body []byte
	// SidecarOf, when set, makes the file a sidecar that the format keeps
	// with another file of the same version: the path of that owner. A
	// scenario that deletes, copies, moves or restores a version's files
	// one at a time names the owner alone and checks that its sidecars
	// went with it.
	SidecarOf string
}

File is one file of a version as a client deploys it.

type Format

type Format struct {
	// Type is the package type of the repositories the suite creates.
	Type repo.PackageType
	// Layout, when set, is the repositories' repoLayoutRef.
	Layout string
	// Local, when set, adjusts each local repository the suite creates
	// before it is stored, for a format that serves only some of its
	// type's repositories, as Terraform's terraformType chooses modules or
	// providers (decision 0040).
	Local func(*repo.Config)
	// Handler is the format; nil means the one formats.For picks for Type.
	Handler format.Handler
	// Version returns version v of package p as deployed for the nth time.
	// The suite names packages "alpha" and "beta" and versions "1.0" and
	// "2.0"; the fixture maps them to its ecosystem's names. Every n gives
	// the same paths, and n > 0 changes the content of at least one file,
	// so a redeploy overwrites.
	Version func(p, v string, n int) Version
	// Properties are the property sets the suite applies in turn to a
	// version's files: a format whose index follows properties names the
	// ones it reads. Nil means a set the format does not read.
	Properties []types.Properties
	// Work lists the kinds of work the format queues on a deploy, keyed by
	// package. Each committed deploy leaves exactly one item of each per
	// package; a kind listed in neither Work nor RepoWork must never be
	// queued.
	Work []string
	// RepoWork lists the kinds of work the format queues keyed by the
	// repository's key alone, as Helm's index.yaml is (decision 0039): the
	// key a reindex of the repository is queued under too (decision 0033).
	// Every committed write that changes a repository's versions leaves
	// exactly one item of each for that repository, however many packages
	// it touched, and none for a repository it left alone.
	RepoWork []string
	// NoRemoteCache marks a format that does not index a remote
	// repository's cache yet, as decision 0018 has the npm, Go and Maven
	// formats do. Docker sets it until its remote repositories come in P9.
	NoRemoteCache bool
}

Format is a format under the contract.

type Version

type Version struct {
	// Package and Version are what the index calls it; both are empty for
	// a format that keeps no index.
	Package, Version string
	// Files are deployed in order.
	Files []File
	// Linked are the paths of the files the index links to the version;
	// nil means every file but the sidecars, which are never linked.
	Linked []string
}

Version is one version of a package as a client deploys it.

Jump to

Keyboard shortcuts

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