bdd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 24 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 bdd runs Gherkin feature files against a project's .http requests with a fixed step vocabulary, using godog embedded in the binary.

Index

Constants

View Source
const (
	ExitPassed    = runner.ExitOK
	ExitFailed    = runner.ExitAssert
	ExitUsage     = runner.ExitUsage
	ExitTransport = runner.ExitTransport
)

Exit codes from Run, aligned with the rest of apic.

Variables

View Source
var Formats = []string{"pretty", "progress", "cucumber", "junit"}

Formats lists the accepted --format values.

View Source
var Vocabulary = []struct{ Pattern, Purpose string }{
	{`the environment is "<name>"`, "switch the scenario to another environment"},
	{`the variable "<name>" is "<value>"`, "set a variable for later steps"},
	{`the variables:` + " (table name | value)", "set several variables"},
	{`I run "<request>"`, "send a request by id; fails if its # @assert or # @capture fail"},
	{`I run "<request>" with:` + " (table name | value)", "send a request with variables"},
	{`I run the file "<file.http>"`, "send every request in a file, stopping at the first failure"},
	{`the response status is <n>` + " / is not <n>", "status code"},
	{`the response is successful` + " / a client error / a server error", "2xx / 4xx / 5xx"},
	{`the response body "<path>" is "<value>"`, `also: is not, contains, starts with, ends with, matches; <path> like $.items[0].id, $..id or $.items[?(@.done == true)].id`},
	{`the response header "<name>" is "<value>"`, "same operators as for the body"},
	{`the response cookie "<name>" is "<value>"`, "a cookie the response set; same operators, also exists / does not exist"},
	{`the response body "<path>" exists` + " / does not exist", "presence of a value"},
	{`the response body "<path>" has length <n>`, "characters of a string, elements of an array, keys of an object"},
	{`the response body "<path>" is a number`, "also: a string, an integer, a boolean, an array, an object, null"},
	{`the response body "<path>" is empty` + " / is not empty", "an empty string, array or object"},
	{`the response body matches the schema "<file.json>"`, `JSON Schema (2020-12 or draft-07), path from the project root; also: the response body "<path>" matches the schema "<file.json>"`},
	{`the response body is:` + " (doc string)", "semantic JSON equality"},
	{`the response body contains:` + " (doc string)", "JSON subset match"},
	{`the response time is under <n> ms`, "round-trip time"},
	{`I capture the response body "<path>" as "<name>"`, "store a value; also: header, cookie"},
}

Vocabulary documents the built-in steps for `apic test --steps` and the docs.

Functions

func FeatureFiles

func FeatureFiles(o Options) ([]string, error)

FeatureFiles lists every .feature file the run would read, after the same root checks as the run itself. Callers use it to protect inputs.

func Phrases

func Phrases(p *project.Project) map[string]*httpfile.Request

Phrases lists every declared phrase with the request it runs, for `list`.

func Run

func Run(ctx context.Context, opts Options) (int, error)

Run executes the features and returns an exit code. err carries the typed failure when the run ended on a usage problem (exit 2: no features, bad phrase, unknown environment, unknown request, missing variable) or a transport problem (exit 3); assertion failures are reported by code only.

Types

type Config

type Config struct {
	Project    *project.Project
	Env        string
	Vars       map[string]string
	UseSession bool // read and write .apic/session.json instead of an isolated in-memory session
	Timeout    time.Duration
	Insecure   bool
	Redact     bool
	Cookies    bool // keep a cookie jar (in memory per scenario, shared on disk under UseSession)
	Stderr     io.Writer
	CACert     string // --cacert, --cert and --key
	Cert       string
	Key        string
	Proxy      string // --proxy and --no-proxy
	NoProxy    bool
	// contains filtered or unexported fields
}

Config is shared by every scenario in a run.

type Failure

type Failure struct {
	Feature  string `json:"feature"`
	Scenario string `json:"scenario"`
	Step     string `json:"step"`
	Status   string `json:"status"`
	Error    string `json:"error,omitempty"`
}

Failure describes one failed or undefined step.

type Options

type Options struct {
	Config
	Paths         []string        // feature files or directories; relative paths resolve against the project root
	Features      []godog.Feature // in-memory features (tests and MCP); used when Paths is empty
	Format        string          // one of Formats; default pretty
	Output        io.Writer       // report destination; default os.Stdout
	Tags          string          // godog tag expression, e.g. "@smoke && ~@slow"
	StopOnFailure bool
	NoColors      bool
}

Options controls one run.

type Summary

type Summary struct {
	OK        bool      `json:"ok"` // no scenario failed; check Scenarios for how many ran
	Scenarios int       `json:"scenarios"`
	Passed    int       `json:"passed"`
	Failed    int       `json:"failed"`
	Skipped   int       `json:"skipped"` // not run, e.g. after --stop-on-failure
	Undefined int       `json:"undefined"`
	Failures  []Failure `json:"failures,omitempty"`
}

Summary is the machine-readable outcome of a run, derived from the cucumber JSON report.

func RunSummary

func RunSummary(ctx context.Context, opts Options) (*Summary, []byte, int, error)

RunSummary runs with the cucumber formatter into memory and returns the parsed summary plus the raw report. Used by MCP and tests. When a usage or transport error ends the run, the summary of what ran is still returned alongside the error whenever a report was produced.

func Summarize

func Summarize(report []byte) (*Summary, error)

Summarize parses a cucumber JSON report.

Jump to

Keyboard shortcuts

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