scenario

package
v8.82.3 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package scenario is the format of e2e/scenarios/<slug>/: scenario.yaml (the command line, the environment, the mocks' response sequences) and expected.json (the exit code and the JSON document, "*" for a value the scenario does not pin). e2e/README.md documents it for the people who add scenarios; this package is where the harness reads it.

Index

Constants

View Source
const (
	ScenarioFile = "scenario.yaml"
	ExpectedFile = "expected.json"
)

File names of a scenario directory.

View Source
const DefaultTimeout = 60 * time.Second

DefaultTimeout bounds one scenario's run of the binary.

View Source
const Wildcard = "*"

Wildcard is the expected value that matches anything.

Variables

This section is empty.

Functions

func Discover

func Discover(root string) ([]string, error)

Discover lists the directories under root that hold a scenario.yaml, sorted by name.

func Load

func Load(dir string) (*Scenario, *Expected, error)

Load reads a scenario directory. Unknown fields in either file are errors, so a misspelt key fails the scenario instead of being ignored.

func Match

func Match(expected, actual any) error

Match compares an actual JSON document with the expected one, both as decoded by encoding/json: objects need the same keys with matching values, arrays the same length with matching elements, scalars equality, and the Wildcard matches any value. The error names the first difference by path.

Types

type Expected

type Expected struct {
	// ExitCode the binary must exit with.
	ExitCode int `json:"exitCode"`
	// JSON is the document stdout must carry, "*" standing for any value;
	// left out, stdout is not compared.
	JSON json.RawMessage `json:"json"`
}

Expected is expected.json.

func (Expected) ComparesJSON

func (e Expected) ComparesJSON() bool

ComparesJSON says whether stdout is compared.

type Mock

type Mock struct {
	Routes sequence.Routes `yaml:"routes"`
}

Mock is one mock's script.

type RegistryMock

type RegistryMock struct {
	Mock `yaml:",inline"`
	// StaleLogin makes the registry refuse every request that carries
	// credentials with 401; anonymous requests are served by the routes.
	StaleLogin bool `yaml:"staleLogin"`
}

RegistryMock is a registry's script and state.

type Scenario

type Scenario struct {
	// Description says what the scenario proves, one line.
	Description string `yaml:"description"`
	// Args is devctl's command line without the binary.
	Args []string `yaml:"args"`
	// Env is added to the environment the harness builds; a variable named
	// here replaces the harness's value.
	Env map[string]string `yaml:"env"`
	// Timeout for the run; DefaultTimeout when left out.
	Timeout time.Duration `yaml:"timeout"`
	// Keyring is written as JSON to the file DEVCTL_KEYRING_FILE names; left
	// out, the file does not exist.
	Keyring any `yaml:"keyring"`
	// GitHub, CircleCI, Registry and PrivateRegistry script the mocks.
	GitHub          Mock         `yaml:"github"`
	CircleCI        Mock         `yaml:"circleci"`
	Registry        RegistryMock `yaml:"registry"`
	PrivateRegistry RegistryMock `yaml:"privateRegistry"`
}

Scenario is scenario.yaml.

Jump to

Keyboard shortcuts

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