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 ¶
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 ¶
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 ¶
Register puts Kind into proposal.Kinds with the limits, and returns the function that removes it (for t.Cleanup).
func Violations ¶
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 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 (*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 ¶
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.