Documentation
¶
Overview ¶
Code generated by mkunion. DO NOT EDIT.
Code generated by mkunion. DO NOT EDIT.
Code generated by mkunion. DO NOT EDIT.
Code generated by mkunion. DO NOT EDIT.
Index ¶
- func CaseShape() shape.Shape
- func InferTransitionShape() shape.Shape
- func MachineShape() shape.Shape
- func ParsedTransitionShape() shape.Shape
- func StepShape() shape.Shape
- func SuiteShape() shape.Shape
- type Case
- func (suitcase *Case[D, C, S]) AfterCommand(f func(testing.TB, D)) *Case[D, C, S]
- func (suitcase *Case[D, C, S]) BeforeCommand(f func(testing.TB, D)) *Case[D, C, S]
- func (suitcase *Case[D, C, S]) ForkCase(t *testing.T, name string, f func(t *testing.T, c *Case[D, C, S])) *Case[D, C, S]
- func (suitcase *Case[D, C, S]) GivenCommand(c C) *Case[D, C, S]
- func (suitcase *Case[D, C, S]) ThenState(t *testing.T, o S) *Case[D, C, S]
- func (suitcase *Case[D, C, S]) ThenStateAndError(t *testing.T, state S, err error) *Case[D, C, S]
- type InferTransition
- func (t *InferTransition[Transition, State]) Record(tr Transition, prev, curr State, errAfterTransition error)
- func (t *InferTransition[Transition, State]) ToMermaid() string
- func (t *InferTransition[Transition, State]) WithErrorTransitions(flag bool) *InferTransition[Transition, State]
- func (t *InferTransition[Transition, State]) WithTitle(name string) *InferTransition[Transition, State]
- type Machine
- type ParsedTransition
- type Step
- type Suite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InferTransitionShape ¶ added in v1.25.0
func MachineShape ¶ added in v1.25.0
func ParsedTransitionShape ¶ added in v1.25.0
func SuiteShape ¶ added in v1.25.0
Types ¶
type Case ¶ added in v1.17.0
type Case[D, C, S any] struct { // contains filtered or unexported fields }
func (*Case[D, C, S]) AfterCommand ¶ added in v1.25.0
AfterCommand is optional, if provided it will be called after command is executed useful when you want to assert some data after command is executed, like what function were called, and with what arguments
func (*Case[D, C, S]) BeforeCommand ¶ added in v1.25.0
BeforeCommand is optional, if provided it will be called before command is executed useful when you want to prepare some data before command is executed, like change dependency to return error, or change some state
func (*Case[D, C, S]) ForkCase ¶ added in v1.17.1
func (suitcase *Case[D, C, S]) ForkCase(t *testing.T, name string, f func(t *testing.T, c *Case[D, C, S])) *Case[D, C, S]
ForkCase takes previous state of machine and allows to apply another case from this point onward it's useful when you want to test multiple scenarios from one state
func (*Case[D, C, S]) GivenCommand ¶ added in v1.17.0
GivenCommand starts building assertion that when command is applied to machine, it will result in given state or error.
func (*Case[D, C, S]) ThenState ¶ added in v1.17.0
ThenState asserts that command applied to machine will result in given state implicitly assumes that error is nil
func (*Case[D, C, S]) ThenStateAndError ¶ added in v1.17.0
ThenStateAndError asserts that command applied to machine will result in given state and error state is required because we want to know what is the expected state after command fails to be applied, and return error. state most of the time shouldn't be modified, and explicit definition of state help to make this behaviour explicit.
type InferTransition ¶ added in v1.16.1
type InferTransition[Transition, State any] struct { // contains filtered or unexported fields }
func NewInferTransition ¶ added in v1.16.1
func NewInferTransition[Transition, State any]() *InferTransition[Transition, State]
NewInferTransition creates a helper to infer state machine transitions.
func (*InferTransition[Transition, State]) Record ¶ added in v1.16.1
func (t *InferTransition[Transition, State]) Record(tr Transition, prev, curr State, errAfterTransition error)
Record records a transition.
func (*InferTransition[Transition, State]) ToMermaid ¶ added in v1.16.1
func (t *InferTransition[Transition, State]) ToMermaid() string
ToMermaid returns a string in Mermaid format. https://mermaid-js.github.io/mermaid/#/stateDiagram
func (*InferTransition[Transition, State]) WithErrorTransitions ¶ added in v1.16.1
func (t *InferTransition[Transition, State]) WithErrorTransitions(flag bool) *InferTransition[Transition, State]
func (*InferTransition[Transition, State]) WithTitle ¶ added in v1.16.1
func (t *InferTransition[Transition, State]) WithTitle(name string) *InferTransition[Transition, State]
type Machine ¶
type Machine[D, C, S any] struct { // contains filtered or unexported fields }
func NewMachine ¶ added in v1.25.0
func NewSimpleMachine ¶
type ParsedTransition ¶ added in v1.25.0
ParsedTransition represents a transition parsed from a mermaid diagram
func ParseMermaid ¶ added in v1.25.0
func ParseMermaid(mermaidContent string) ([]ParsedTransition, error)
ParseMermaid parses a mermaid diagram and extracts transitions
type Step ¶ added in v1.25.0
type Step[D, C, S any] struct { // Name human readable description of the test case. It's required Name string // InitState is optional, if not provided it will be nil // and when step is part of sequence, then state will be inherited from previous step InitState S // GivenCommand is the command that will be applied to the machine. It's required GivenCommand C // BeforeCommand is optional, if provided it will be called before command is executed BeforeCommand func(t testing.TB, x D) // AfterCommand is optional, if provided it will be called after command is executed AfterCommand func(t testing.TB, x D) // ExpectedState is the expected state after command is executed. It's required, but can be nil ExpectedState S // ExpectedErr is the expected error after command is executed. It's required, but can be nil ExpectedErr error }
Step is a single test case that describe state machine transition
type Suite ¶ added in v1.17.0
type Suite[D, C, S any] struct { // contains filtered or unexported fields }
func NewTestSuite ¶ added in v1.17.0
func (*Suite[D, C, S]) AssertSelfDocumentStateDiagram ¶ added in v1.17.0
AssertSelfDocumentStateDiagram help to self document state machine transitions, just by running tests. It will compare current state diagram with stored in file. It will fail assertion if they are not equal. This may happen, when tests are changed, or state machine is changed. In both then visual inspection of state diagram helps to double-check if changes are correct. And use diagrams in documentation.
If file does not exist, function will return true, to indicate that file should be created. For this purpose call SelfDocumentStateDiagram.
func (*Suite[D, C, S]) SelfDocumentStateDiagram ¶ added in v1.17.0
SelfDocumentStateDiagram help to self document state machine transitions, just by running tests. It will always overwrite stored state diagram files, useful in TDD loop, when tests are being written.