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 ¶
- type Engine
- type GlobalStorage
- type ScriptContext
- func (c *ScriptContext) GetEnvVar(name string) string
- func (c *ScriptContext) GetGlobalVar(name string) any
- func (c *ScriptContext) GetGlobalVarAsString(name string) string
- func (c *ScriptContext) MergeGlobalVars(vars map[string]any)
- func (c *ScriptContext) SetEnvVar(name, value string)
- func (c *ScriptContext) SetGlobalVar(name string, value any)
- func (c *ScriptContext) SetRequest(req *models.HttpRequest)
- func (c *ScriptContext) SetResponse(resp *models.HttpResponse)
- type ScriptResult
- type TestResult
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 (*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) 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 ¶
TestResult represents the result of a single test