behaviortest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 36 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 behaviortest runs a behavior's examples and refusals against a fake host, so a behavior's provider is tested from its definition. A behavior's own test calls Run; osapi dsl behavior create writes that line.

Index

Constants

View Source
const Hostname = "test-host"

Hostname is the fake host's name.

Variables

View Source
var Now = time.Date(2026, time.January, 2, 3, 4, 5, 0, time.UTC)

Now is the fake host's time, for each example: an output that reads the clock, such as an uptime, is computed from it.

Functions

func ChainProblems

func ChainProblems(
	b *behavior.Behavior,
) []behavior.Problem

ChainProblems are the problems of the chain rules that need a run of the examples of b: a call to a behavior that the caller does not require, a call that gives a secret to a field that is not a secret.Value, and a requirement of b that no example calls. osapi dsl chain validate reports them, and Run fails the tests of b on them.

func Check

func Check(
	b *behavior.Behavior,
) []string

Check runs every example of every method of b on a fake host, once per platform b declares, with that platform's provider, and returns what went wrong. For each example:

  • the output is the example's Output;
  • each declared effect holds: a file written or removed, a command run;
  • a write that reports changed declares at least one effect;
  • a write run a second time reports changed: false;
  • with each filesystem, command and store call failing in turn, and with each store read returning a damaged record in turn, the method returns rather than panics.

For each refusal declared with Fails, the call fails with an error that contains its text. And each string input field is probed with hostile values, as checkProbes describes.

func ReadsThroughRunCmd

func ReadsThroughRunCmd(
	m *hostmocks.MockExec,
)

ReadsThroughRunCmd makes m answer each RunReadCmd, the read that gohai runs, with m's own RunCmd: a test of a provider then states each command once, as RunCmd, whether gohai or the provider runs it.

func Run

func Run(
	t testing.TB,
	b *behavior.Behavior,
)

Run checks b with Check and reports each problem as a test error. It also reads the Go files of the test's directory, which is the package of b, and fails a direct call of a method of a behavior b requires.

Types

type ChainRun

type ChainRun struct {
	Method   string                `json:"method"`
	Example  string                `json:"example"`
	Platform behavior.PlatformName `json:"platform"`
	Root     *behavior.Step        `json:"root"`
}

ChainRun is one example of a method, run on a fake host, with each Call that it made: the root step is the method, and its steps are the calls.

func Chains

func Chains(
	b *behavior.Behavior,
) []ChainRun

Chains runs each example of each method of b once, on the first platform that serves it, as Check does, and records its calls. An example that the fake host cannot set up is left out: Check reports it.

Jump to

Keyboard shortcuts

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