scripting

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package scripting provides a JavaScript execution engine for pre-request and post-response scripts, with built-in utilities for assertions, crypto, and variable management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine executes JavaScript scripts for HTTP request/response handling

func NewEngine

func NewEngine() *Engine

NewEngine creates a new scripting engine

func (*Engine) Execute

func (e *Engine) Execute(script string, ctx *ScriptContext) (*ScriptResult, error)

Execute runs a script with the given context

func (*Engine) ExecuteWithContext added in v0.2.10

func (e *Engine) ExecuteWithContext(ctx context.Context, script string, scriptCtx *ScriptContext) (*ScriptResult, error)

ExecuteWithContext runs a script with the given context and supports cancellation. If the context is canceled or times out, the script execution will be interrupted.

type GlobalStorage

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

GlobalStorage manages global variables across requests

func (*GlobalStorage) Clear

func (g *GlobalStorage) Clear(name string)

Clear removes a variable

func (*GlobalStorage) ClearAll

func (g *GlobalStorage) ClearAll()

ClearAll removes all variables

func (*GlobalStorage) Get

func (g *GlobalStorage) Get(name string) any

Get retrieves a variable

func (*GlobalStorage) IsEmpty

func (g *GlobalStorage) IsEmpty() bool

IsEmpty checks if the storage is empty

func (*GlobalStorage) Set

func (g *GlobalStorage) Set(name string, value any)

Set stores a variable

type ScriptContext

type ScriptContext struct {
	Request    *models.HttpRequest
	Response   *models.HttpResponse
	GlobalVars map[string]any
	EnvVars    map[string]string
}

ScriptContext holds all the context needed for script execution

func NewScriptContext

func NewScriptContext() *ScriptContext

NewScriptContext creates a new script context

func (*ScriptContext) GetEnvVar

func (c *ScriptContext) GetEnvVar(name string) string

GetEnvVar gets an environment variable

func (*ScriptContext) GetGlobalVar

func (c *ScriptContext) GetGlobalVar(name string) any

GetGlobalVar gets a global variable

func (*ScriptContext) GetGlobalVarAsString

func (c *ScriptContext) GetGlobalVarAsString(name string) string

GetGlobalVarAsString gets a global variable as a string

func (*ScriptContext) MergeGlobalVars

func (c *ScriptContext) MergeGlobalVars(vars map[string]any)

MergeGlobalVars merges the given global vars into the context

func (*ScriptContext) SetEnvVar

func (c *ScriptContext) SetEnvVar(name, value string)

SetEnvVar sets an environment variable

func (*ScriptContext) SetGlobalVar

func (c *ScriptContext) SetGlobalVar(name string, value any)

SetGlobalVar sets a global variable

func (*ScriptContext) SetRequest

func (c *ScriptContext) SetRequest(req *models.HttpRequest)

SetRequest sets the request in the context

func (*ScriptContext) SetResponse

func (c *ScriptContext) SetResponse(resp *models.HttpResponse)

SetResponse sets the response in the context

type ScriptResult

type ScriptResult struct {
	Tests      []TestResult
	Logs       []string
	Error      error
	GlobalVars map[string]any
}

ScriptResult contains the results of script execution

type TestResult

type TestResult struct {
	Name   string
	Passed bool
	Error  string
}

TestResult represents the result of a single test

Jump to

Keyboard shortcuts

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