Documentation
¶
Overview ¶
Package chain is the chain group of commands, osapi dsl chain: the behaviors that a behavior calls on the same host, in the same job.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Group = command.Register(command.Define( "chain", "Show and check the chains of behaviors that a behavior calls", command.Under(command.ParentDSL), command.Long("A behavior that requires others calls them on the same host, in the same\n"+ "job: dns calls netplan, and netplan calls managedfile. That is a chain, named\n"+ "by the behavior at its top. `behavior.Requires` on each behavior makes it;\n"+ "it is not declared on its own. These commands read the definitions in the\n"+ "binary, and run the examples on the fake host that `go test` uses. Thus they\n"+ "need no config file and no controller, and show what the code does now."), command.Uses[Deps](), command.SubDoc("spec", "Print how to build a chain, and the building blocks of this binary"), command.Method[ListInput, ListOutput]("list"). Short("List each behavior in a chain: what it calls, and what calls it"). Long("**Chain** is the tree of the behaviors that a behavior calls, down to the\n"+ "last one. A building block, with `Internal`, is in the list for the\n"+ "behaviors that call it."). Example(""). Prints(sampleList). Example("--json"). Handle(List), command.Method[GetInput, GetOutput]("get"). Short("Show a chain: its tree, and what each call of each example sends and gets"). Long("It runs each example of the behavior on the fake host that `go test` uses,\n"+ "and records each `behavior.Call`: the behavior, the method, the input, and\n"+ "the output or the error. The table cuts each input and output; `--json`\n"+ "has them in full, under `runs`. An input field tagged `secret` shows as\n"+ "`[redacted]`."). Example("--name dns"). Prints(sampleGet). Example("--name dns --json"). Fails("no name", GetInput{}). Handle(Get), command.Method[ValidateInput, ValidateOutput]("validate"). Short("Check every chain against the chain rules"). Long("It prints each problem with its behavior, method, rule and message, then\n"+ "the fix of each rule, and exits 1 when a rule fails. `osapi dsl behavior\n"+ "validate` checks the rules that hold when the behaviors are built, and\n"+ "`go test` checks the ones that need a run of the examples.\n\n"+ "The rules:\n\n"+behavior.ChainChecks.Help()). Example(""). Prints(sampleValidate). Example("--json"). Handle(Validate), command.Method[SpecInput, SpecOutput]("get"). Sub("spec"). Short("Print how to build a chain, and the building blocks of this binary"). Long("Print what a chain is, how a behavior builds on others and calls them, what\n"+ "happens when a step fails, and each building block of this binary. Read it\n"+ "before a behavior requires another, then check the result with `osapi\n"+ "dsl chain validate`."). Example(""). Prints(sampleSpec). Example("--json"). Handle(Spec), ))
Group is the chain group's definition: osapi dsl chain. A chain is the behaviors that a behavior calls on the same host, in the same job, and the ones that those call.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct {
Call string `json:"call"`
Sends string `json:"sends"`
Gets string `json:"gets"`
}
Call is one call of an example: what it sends and what it gets, as the fields that have a value. --json has each in full, under runs.
type Deps ¶
type Deps struct {
Behaviors func() []*behavior.Behavior
// Runs runs each example of a behavior on the fake host, and records
// its calls: behaviortest.Chains.
Runs func(b *behavior.Behavior) []behaviortest.ChainRun
// Problems are the chain problems that hold when the behaviors are
// built: behavior.ChainProblems.
Problems func() []behavior.Problem
// RunProblems are the chain problems of a behavior that need a run of
// its examples: behaviortest.ChainProblems.
RunProblems func(b *behavior.Behavior) []behavior.Problem
Spec func() guide.Spec
}
Deps is what the methods use: the behaviors, the runs of their examples, the chain problems, and the spec of a chain.
type ExampleCalls ¶
ExampleCalls is one example of a method, and the calls that it makes, each under the call that made it.
type GetInput ¶
type GetInput struct {
Name string `json:"name" validate:"required" doc:"The behavior, from osapi dsl chain list"`
}
GetInput names the behavior at the top of the chain.
type GetOutput ¶
type GetOutput struct {
Behavior string ` json:"behavior"`
Chain string ` json:"chain"`
Calls []string ` json:"calls" none:"none"`
UsedBy []string ` json:"used_by" none:"none" label:"Used by"`
Examples []ExampleCalls ` json:"examples" empty:"No example calls another behavior." table:"sections"`
Runs []behaviortest.ChainRun `` /* 128-byte string literal not displayed */
// contains filtered or unexported fields
}
GetOutput is one chain: its tree, and the calls that each example of the behavior makes, with what each sends and gets.
type ListOutput ¶
type ListOutput struct {
Items []Summary ` json:"items"`
// contains filtered or unexported fields
}
ListOutput is each behavior in a chain: each one that calls others, which has a chain page, and each one that only others call.
type SpecOutput ¶
SpecOutput is each kind of term of a chain, with its terms.
type Summary ¶
type Summary struct {
Behavior string `json:"behavior"`
Internal bool `json:"internal,omitempty"`
Chain string `json:"chain"`
Calls []string `json:"calls" none:"none"`
UsedBy []string `json:"used_by" none:"none" label:"Used by"`
}
Summary is one behavior in a chain: the tree of the behaviors that it calls, and the behaviors that call it.
type ValidateInput ¶
type ValidateInput struct{}
ValidateInput is the input of validate, which has none.
type ValidateOutput ¶
type ValidateOutput struct {
Behaviors int ` json:"behaviors"`
Valid bool ` json:"valid"`
Problems []behavior.Problem ` json:"problems,omitempty"`
Fixes map[string]any ` json:"fixes,omitempty"`
// contains filtered or unexported fields
}
ValidateOutput is each problem of each chain, and the fix of each rule that one breaks.
func Validate ¶
func Validate( _ context.Context, d Deps, _ ValidateInput, ) (ValidateOutput, error)
Validate checks every chain against the chain rules, and fails when one breaks.