proposaltest

package
v0.2.2-dev.5 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proposaltest holds what the tests of the panel's proposals share: a made-up kind with an applier that keeps the contract of proposal.Applier, and ApplierContract, which every real applier of a kind must pass.

Index

Constants

View Source
const Kind = "widget"

Kind is the made-up kind the tests use: a value that is changed from one string to another (a real kind's change is a port or a target). Register it with proposal.Kinds before use (Register).

Variables

This section is empty.

Functions

func ApplierContract

func ApplierContract(t *testing.T, setup Setup)

ApplierContract runs the contract of proposal.Applier against a kind: the applier is called on every pass while its proposal applies, so a repeat, a restart and a change by the owner must all be harmless:

  • called again and again it reaches one result and keeps it, and writes nothing after the value is To;
  • after a restart (a new applier, nothing in memory) it carries on from where the world is;
  • when the world already holds To, it writes nothing and answers applied;
  • when the owner changed the value to something else, it writes nothing and answers stale (changed_meanwhile), before the first write and after To was written alike;
  • when the node refuses (Reject), the old value is back and the answer is failed.

func Register

func Register(limits proposal.Limits, publicValues bool) func()

Register puts Kind into proposal.Kinds with the limits, and returns the function that removes it (for t.Cleanup).

func Violations

func Violations(c Case) []string

Violations is the contract as data: the lines it complains about for the case, for the tests of the contract itself.

Types

type Case

type Case struct {
	// Proposal is the applying proposal; Change.From is what the world holds now, Change.To what the applier brings about.
	Proposal store.Proposal
	// Applier is the applier under test. Restart builds a new one over the same world, with nothing in memory: the panel after
	// a restart. Nil means the applier keeps nothing and may be used again.
	Applier func() proposal.Applier
	Restart func() proposal.Applier
	// Get reads the value of the world; Set changes it as the owner would by hand (neither From nor To).
	Get func() string
	Set func(v string)
	// Settle lets the world move on between two calls (the node reports that it works with the value). Nil: nothing to wait for.
	Settle func()
	// Reject makes the node refuse the new value; with it the contract also checks that the old value is put back and the
	// result is failed. Nil: the kind has no such step.
	Reject func()
}

Case is one world of a kind, with its proposal applying (from the value the world holds, to the value to move to). Every field but Settle and Reject is required.

type Setup

type Setup func(t *testing.T) Case

Setup is what a kind gives the contract: a fresh world for each case.

type World

type World struct {
	Writes  int // how many times the value was written
	Applies int // how many times the applier was called
	// contains filtered or unexported fields
}

World is the thing a Fake changes and the node that has to accept it: one value, and whether the node works with it.

func NewWorld

func NewWorld(value string) *World

NewWorld is a world that holds value.

func (*World) AlwaysConfirm

func (w *World) AlwaysConfirm()

AlwaysConfirm makes the node accept every new value at once, so one pass of the applier ends the proposal.

func (*World) Applier

func (w *World) Applier() proposal.Applier

Applier is the applier of Kind over the world. It keeps the contract: a write that compares From, nothing written when the value already is To, "changed_meanwhile" for any other value, and the node's answer checked at the end.

func (*World) Confirm

func (w *World) Confirm()

Confirm makes the node accept the value it holds (the next check of the applier finds it working).

func (*World) Get

func (w *World) Get() string

Get is the value now.

func (*World) Reject

func (w *World) Reject()

Reject makes the node refuse the value it holds.

func (*World) Set

func (w *World) Set(v string)

Set changes the value, as the owner would by hand; the node has not been told.

Jump to

Keyboard shortcuts

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