Help us shape the future of Go! Take the 2026 Go Developer Survey

engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

HTTP dialing stays behind Sender. This package owns scenario execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchPath

func MatchPath(got, pattern string) (map[string]any, bool)

MatchPath matches literal segments and captures {name} path parameters.

func Register

func Register(name string, fn func([]any) (any, error)) error

Register adds a function to the gi and karate objects for later scenarios. Built-in names are rejected. Unregister removes a previous registration.

func Unregister

func Unregister(name string)

Types

type Call

type Call struct {
	Method    string
	URL       string
	Header    map[string][]string
	Cookies   [][2]string
	Jar       http.CookieJar
	Body      []byte
	Follow    bool
	Transport TransportSettings
}

type Embed

type Embed struct {
	Name string
	Mime string
	Data []byte
}

Embed is one report attachment produced by karate.embed or a screenshot.

type Exchange

type Exchange struct {
	Started         time.Time
	Method          string
	URL             string
	Status          int
	Duration        time.Duration
	RequestHeaders  map[string]string
	RequestBody     string
	ResponseHeaders map[string]string
	ResponseBody    string
	Error           string
	Endpoint        string
}

type FileResult

type FileResult struct {
	Path      string
	Name      string
	Scenarios []ScenarioResult
	Duration  time.Duration
	Started   time.Time
}

func RunFile

func RunFile(ctx context.Context, f *feature.File, opt Options) (FileResult, error)

Background steps are already inlined into each scenario.

func RunFiles

func RunFiles(ctx context.Context, files []*feature.File, opt Options, done func(FileResult)) ([]FileResult, error)

RunFiles runs every file. One file uses Jobs across its scenarios. Several files use Jobs across files, and each file stays in order. done, when set, is called once per file, one file at a time.

func (FileResult) Passed

func (f FileResult) Passed() bool
type Link struct {
	Send    func(context.Context, any) error
	Receive func(context.Context) (any, error)
	Call    func(context.Context, string, any) (any, error)
	Open    func(context.Context, string) (Stream, error)
	Close   func() error
}

Link carries only the operations a protocol actually implements.

type MockRuntime

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

MockRuntime owns a persistent scenario VM. Its caller must serialize requests. Background executes once; request variables and response metadata are reset for each request, while user-defined state remains in the same JS runtime.

func NewMockRuntime

func NewMockRuntime(ctx context.Context, f *feature.File, prepare func(*script.VM)) (*MockRuntime, error)

func (*MockRuntime) Run

func (m *MockRuntime) Run(ctx context.Context, vars map[string]any) ScenarioResult

type Options

type Options struct {
	Vars          map[string]any
	HTTP          Sender
	Stdout        io.Writer
	Jobs          int
	Tag           string
	LoadMode      bool
	Mock          bool
	VU            int
	Iter          int
	Timeout       time.Duration
	OnRequest     func(Exchange)
	BeforeRequest func(context.Context) error
	Prepare       func(*script.VM)
	Dial          func(context.Context, string, map[string]any) (Link, error)
	NewPage       func(context.Context) (Page, error)
	Depth         int
	Env           string
	Suite         *suite.Suite
	SkipHooks     bool
	Stack         []string
	// contains filtered or unexported fields
}

type Page

type Page interface {
	Open(ctx context.Context, url string) error
	Click(ctx context.Context, selector string) error
	Fill(ctx context.Context, selector, text string) error
	Text(ctx context.Context, selector string) (string, error)
	Close() error
}

type Reply

type Reply struct {
	URL      string
	Status   int
	Header   map[string][]string
	Body     []byte
	Duration time.Duration
}

type ScenarioResult

type ScenarioResult struct {
	Name           string
	Line           int
	Tags           []string
	Passed         bool
	Canceled       bool
	Skipped        bool
	Miss           bool
	Duration       time.Duration
	Started        time.Time
	Steps          []StepResult
	Error          string
	Vars           map[string]any
	Defined        map[string]bool
	ReportDisabled bool
}

func RunScenario

func RunScenario(ctx context.Context, f *feature.File, sc feature.Scenario, opt Options) ScenarioResult

type Sender

type Sender interface {
	Send(ctx context.Context, call Call) (Reply, error)
}

type StepResult

type StepResult struct {
	Started  time.Time
	Line     int
	Keyword  string
	Text     string
	Passed   bool
	Canceled bool
	Duration time.Duration
	Error    string
	Diff     string
	Label    string
	Output   string
	HTTP     *Exchange
	Calls    []StepResult
	Embeds   []Embed
}

type Stream

type Stream struct {
	Send      func(context.Context, any) error
	Receive   func(context.Context) (any, error)
	CloseSend func() error
	Close     func() error
}

Stream is one streaming call. CloseSend half-closes the client side. Close releases the call.

type TransportSettings

type TransportSettings struct {
	TLSConfigured        bool
	TrustAll             bool
	TLSVersion           uint16
	CACert, Cert, Key    string
	ProxySet             bool
	Proxy, NonProxyHosts string
	ConnectTimeout       time.Duration
}

TransportSettings is immutable data, comparable for connection-pool reuse. Default settings preserve the caller's HTTP client's transport.

Jump to

Keyboard shortcuts

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