expect

package
v0.0.0-...-abaeddd Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 26 Imported by: ? 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 expect provides E2E expectation execution and result types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttemptsCell

func AttemptsCell(c CaseResult) string

AttemptsCell is a case's attempts for a report table, such as "2 of 3": blank when no retry was configured or the case was skipped.

func Call

func Call(name, url string) spec.ExternalCheck

func SuitePost

func SuitePost(ctx context.Context, name string, block *spec.SideEffects, o SuitePostOptions) []string

SuitePost runs a spec-level post block (the spec's onFailure or finally), named by its key, once for the suite, resolved the way an expectation is: the spec's env expanded into it once and in its commands' environment, its functions in its templates. It returns the block's warnings; a name nothing declares is one, and the block does not run.

func ValidateExternal

func ValidateExternal(expects spec.Expectations) []error

ValidateExternal checks every external: call across all expect entries — each step's, and each one's onFailure and finally — with the validator a Blueprint's calls go through. Run it after ExpandIncludes, so included calls are checked too.

func ValidateExternalCalls

func ValidateExternalCalls(loc string, calls []spec.ExternalCheck) []error

ValidateExternalCalls checks one external: list; loc prefixes each error. Names are required and unique within the list.

Types

type CaseResult

type CaseResult struct {
	Name     string
	Passed   bool
	Skipped  bool
	Elapsed  time.Duration
	Err      error
	Attempts int `json:"attempts,omitempty"` // attempts run; 0 when skipped
	Retries  int `json:"retries,omitempty"`  // retries configured; omitted when none
	// Warnings are the case's post-block failures: an onFailure or finally
	// operation that failed or whose assertions did not hold. They never
	// change Passed.
	Warnings []string `json:"warnings,omitempty"`
}

CaseResult holds the outcome of a single expectation.

type ImportResult

type ImportResult struct {
	// Path is the import path as declared in imports:
	// (e.g. "./01-basic/e2e.yaml").
	Path string
	// Result is the structured outcome. Nil when the import failed to load or
	// the runner itself errored before producing any expectations.
	Result *Result
	// Err is non-nil when the import failed (load error, Inrun not ready,
	// or one or more expectations failed).
	Err error
}

ImportResult holds the outcome of one imported E2E file in a suite run.

func (ImportResult) Name

func (i ImportResult) Name() string

Name returns the display name — the E2E metadata.name when available, otherwise the import path.

func (ImportResult) Passed

func (i ImportResult) Passed() bool

Passed reports whether this import succeeded.

type ImportResults

type ImportResults []ImportResult

func (ImportResults) Duration

func (r ImportResults) Duration() time.Duration

Duration returns the total elapsed time across all imported suites, including nested imports.

func (ImportResults) Failed

func (r ImportResults) Failed() int

Failed returns the number of failed expectations across all imported suites.

func (ImportResults) Passed

func (r ImportResults) Passed() int

Passed returns the number of passing expectations across all imported suites.

func (ImportResults) PrintImportSummary

func (r ImportResults) PrintImportSummary(suiteName string) error

PrintImportSummary prints the suite results table and returns a non-nil error when any import failed.

func (ImportResults) Skipped

func (r ImportResults) Skipped() int

Skipped returns the number of skipped expectations across all imported suites.

func (ImportResults) Total

func (r ImportResults) Total() int

Total returns the total number of expectations across all imported suites.

type Options

type Options struct {
	WorkDir     string
	MaxFailures int

	CS      kubernetes.Interface
	Cfg     *rest.Config
	Dynamic dynamic.Interface
	Mapper  apimeta.RESTMapper

	// Env is the spec's env; each expectation's own env overlays it.
	Env map[string]string
	// Functions are the template functions expectations start from; nil is
	// KEL's. SpecFunctions are added to them.
	Functions     template.FuncMap
	SpecFunctions []resolver.Function
	// OnFailure is the spec's onFailure: its stop applies to every
	// expectation that doesn't set its own.
	OnFailure *spec.OnFailure
	// Data is what when:/or: conditions read, such as the object under test.
	Data map[string]any
	// Contexts are added to every expectation's env: ${{ ecosystem.… }}.
	Contexts spec.Contexts
	// TemplateData is what templates and CEL read besides env, by key, such
	// as the ecosystem's connection details under ecosystem.
	TemplateData map[string]any
}

Options configure a Runner.

type Result

type Result struct {
	Name      string
	SpecPath  string
	Context   string
	Cluster   string
	StartedAt time.Time
	Cases     []CaseResult
	Elapsed   time.Duration
	Command   string
	// StopReason is non-empty when the run stopped before all expectations ran.
	// Values: "max-failures" (the --max-failures cap was hit) or "step" (an
	// expectation declared onFailure.stop). Empty means the run completed.
	StopReason string
	// StoppedAfter is the number of failures observed when the run stopped.
	// Zero when StopReason is empty.
	StoppedAfter int
	Planned      int // the number of expectations declared in the suite
	// Warnings are the suite onFailure's failures; like a case's, they never
	// change the result.
	Warnings []string
	// SetupFailure is set when the environment or a prepare step failed and
	// stopped the run. The expectations that ran before it are in Cases.
	SetupFailure *SetupFailure
	// Imports contains the results of imported E2E suites.
	Imports ImportResults `json:"-"`
	// Caller identifies the application or integration that invoked jig.
	// It is empty when jig is run directly through its CLI.
	Caller string `json:"caller,omitempty" yaml:"caller,omitempty"`
}

Result holds the outcome of a complete E2E run. It is returned by Run and consumed by inrun push to embed verification metadata into OCI annotations.

func (*Result) AllPassed

func (r *Result) AllPassed() bool

AllPassed returns true when every non-skipped expectation passed.

func (*Result) CallerName

func (r *Result) CallerName() string

CallerName returns the invoking application, defaulting to "jig".

func (*Result) Duration

func (r *Result) Duration() string

Duration returns the total elapsed time as a human-readable string (e.g. "45s").

func (*Result) DurationWithImports

func (r *Result) DurationWithImports() string

DurationWithImports returns the total elapsed time as a human-readable string.

func (*Result) ExtraAttempts

func (r *Result) ExtraAttempts() int

ExtraAttempts returns the total attempts beyond the first, across all cases. A suite where one case passed on try 2 returns 1.

func (*Result) Failed

func (r *Result) Failed() int

Failed returns the number of failed expectations.

func (*Result) Passed

func (r *Result) Passed() int

Passed returns the number of passing expectations.

func (*Result) Retried

func (r *Result) Retried() int

Retried returns the number of cases that took more than one attempt.

func (*Result) Skipped

func (r *Result) Skipped() int

Skipped returns the number of skipped expectations.

func (*Result) Summary

func (r *Result) Summary() string

Summary returns a one-line result string, e.g. "3 of 4 passed, 1 skipped (45s)".

func (*Result) Total

func (r *Result) Total() int

Total returns the total number of expectations.

func (*Result) WithImports

func (r *Result) WithImports() bool

WithImports returns true when the suite has imported E2E suites.

func (*Result) WithImportsDuration

func (r *Result) WithImportsDuration() time.Duration

WithImports returns the total elapsed time across this suite and all imports.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs expectations, group by group, keeping the results, the failure count and the stop across groups: a run calls Run once per after: group, between its steps.

func NewRunner

func NewRunner(opts Options) *Runner

NewRunner returns a Runner for opts.

func (*Runner) Cases

func (r *Runner) Cases() []CaseResult

Cases are the results so far.

func (*Runner) Failures

func (r *Runner) Failures() int

Failures counts the failed expectations so far.

func (*Runner) Record

func (r *Runner) Record(c CaseResult)

Record adds a result made outside the expectations, such as a guard's, counting it as a failure when it didn't pass.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, expects spec.Expectations) bool

Run runs expects in order, recording each result, and reports whether the run stopped: an expectation requested it, or the failure count reached MaxFailures. After a stop, Run runs nothing.

func (*Runner) Stopped

func (r *Runner) Stopped() (error, string)

Stopped reports why the run stopped ("step", "max-failures"), or "" when it hasn't.

type SetupFailure

type SetupFailure struct {
	At  string
	Err string
}

SetupFailure is what stopped a run before its expectations could finish: At is "environment" or the prepare step's name, Err why.

type StepResult

type StepResult struct {
	Attempts   int  // attempts actually run
	Configured int  // 1 + retry count; 1 when no retry is configured
	Skipped    bool // when:/or: gate not met; the expectation did not run
}

StepResult is what one expectation's run produced: the outcome plus how many attempts it took and how many were configured. The runner copies these into the case result for the report.

type SuitePostOptions

type SuitePostOptions struct {
	Env     map[string]string
	WorkDir string
	CS      kubernetes.Interface
	Cfg     *rest.Config

	// Functions are the template functions the block starts from; nil is
	// KEL's. SpecFunctions are added to them.
	Functions     template.FuncMap
	SpecFunctions []resolver.Function

	// Contexts and TemplateData are the run's, as in Options.
	Contexts     spec.Contexts
	TemplateData map[string]any
}

SuitePostOptions is what a spec-level post block needs: the spec's env and functions, and the cluster it runs against.

Directories

Path Synopsis
Package report renders jig results as Markdown, JSON and JUnit XML reports.
Package report renders jig results as Markdown, JSON and JUnit XML reports.

Jump to

Keyboard shortcuts

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