runner

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateAssertion

func ValidateAssertion(assertion Assertion, statusCode int, body []byte, headers http.Header) error

ValidateAssertion checks if a response matches the assertion criteria

Types

type Assertion

type Assertion struct {
	Type     string `yaml:"type"` // status_code, json_path, content_type, header
	Expected any    `yaml:"expected,omitempty"`
	Path     string `yaml:"path,omitempty"`
	Name     string `yaml:"name,omitempty"` // Header name for header assertions
	Exists   bool   `yaml:"exists,omitempty"`
	Equals   string `yaml:"equals,omitempty"`
	Contains string `yaml:"contains,omitempty"`
	Empty    bool   `yaml:"empty,omitempty"` // Check if array/object is empty
}

Assertion defines a validation rule for the response

type FileUpload

type FileUpload struct {
	Field string `yaml:"field"` // Form field name
	Path  string `yaml:"path"`  // Path to the file
}

FileUpload defines a file to be uploaded

type MultipartFile added in v1.4.0

type MultipartFile struct {
	File string `yaml:"file"`
}

MultipartFile defines a file reference within a multipart upload

type Request

type Request struct {
	Method    string                    `yaml:"method"`
	Endpoint  string                    `yaml:"endpoint"`
	Headers   map[string]string         `yaml:"headers,omitempty"`
	Body      map[string]any            `yaml:"body,omitempty"`
	File      *FileUpload               `yaml:"file,omitempty"`
	Multipart map[string]*MultipartFile `yaml:"multipart,omitempty"`
}

Request defines an HTTP request to be made

type Runner

type Runner struct {
	TotalTests  int
	PassedTests int
	FailedTests int
	// contains filtered or unexported fields
}

Runner executes test scenarios

func New

func New(baseURL string, verbose bool) *Runner

New creates a new test runner

func (*Runner) CheckServer

func (r *Runner) CheckServer() error

CheckServer verifies the server is reachable

func (*Runner) GetSummary

func (r *Runner) GetSummary() (int, int, int)

GetSummary returns test execution summary

func (*Runner) Run

func (r *Runner) Run(scenarioFile string) error

Run executes a test scenario from a file

type Scenario

type Scenario struct {
	Name    string `yaml:"name"`
	BaseURL string `yaml:"base_url"`
	Steps   []Step `yaml:"scenarios"`
}

Scenario represents a complete test scenario loaded from YAML

func LoadScenario

func LoadScenario(filename string) (*Scenario, error)

LoadScenario loads and parses a YAML scenario file

type State

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

State manages variables that can be substituted in requests

func NewState

func NewState() *State

NewState creates a new state manager

func (*State) Get

func (s *State) Get(key string) (string, bool)

Get retrieves a variable value

func (*State) Set

func (s *State) Set(key, value string)

Set stores a variable value

func (*State) Substitute

func (s *State) Substitute(text string) string

Substitute replaces {{variable}} placeholders in a string

func (*State) SubstituteMap

func (s *State) SubstituteMap(m map[string]any) map[string]any

SubstituteMap replaces variables in a map[string]any (for request bodies)

func (*State) SubstituteStringMap

func (s *State) SubstituteStringMap(m map[string]string) map[string]string

SubstituteStringMap replaces variables in a map[string]string (for headers)

type Step

type Step struct {
	Name       string            `yaml:"name"`
	Request    Request           `yaml:"request"`
	Assertions []Assertion       `yaml:"assertions"`
	Store      map[string]string `yaml:"store"`
}

Step represents a single test step within a scenario

Jump to

Keyboard shortcuts

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