script

package
v0.1.49 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(container interface{}, element interface{}) bool

AssertContains checks if a string contains a substring or an array contains an element.

func AssertEqual

func AssertEqual(actual, expected interface{}) bool

AssertEqual checks if two values are equal.

func AssertJSONEqual

func AssertJSONEqual(actual, expected string) bool

AssertJSONEqual checks if two JSON strings represent equal values.

func AssertMatch

func AssertMatch(value string, pattern string) bool

AssertMatch checks if a string matches a regex pattern.

func FormatTestResults

func FormatTestResults(results []TestResult) string

FormatTestResults formats test results for display.

Types

type ConsoleHandler

type ConsoleHandler func(level, message string)

ConsoleHandler is a function that handles console output from JavaScript.

type Engine

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

Engine wraps the Goja JavaScript runtime for executing scripts.

func NewEngine

func NewEngine() *Engine

NewEngine creates a new JavaScript execution engine.

func (*Engine) Clone

func (e *Engine) Clone() *Engine

Clone creates a copy of the engine with the same globals and functions.

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, script string) (interface{}, error)

Execute runs a JavaScript script and returns the result.

func (*Engine) ExecuteWithTimeout

func (e *Engine) ExecuteWithTimeout(script string, timeout time.Duration) (interface{}, error)

ExecuteWithTimeout executes a script with a specific timeout.

func (*Engine) GetGlobal

func (e *Engine) GetGlobal(name string) interface{}

GetGlobal gets a global variable value.

func (*Engine) RegisterFunction

func (e *Engine) RegisterFunction(name string, fn interface{})

RegisterFunction registers a Go function to be callable from JavaScript.

func (*Engine) RegisterObject

func (e *Engine) RegisterObject(name string, obj map[string]interface{})

RegisterObject registers an object with properties/methods accessible from JavaScript.

func (*Engine) Reset

func (e *Engine) Reset()

Reset clears the engine state and creates a fresh runtime.

func (*Engine) SetConsoleHandler

func (e *Engine) SetConsoleHandler(handler ConsoleHandler)

SetConsoleHandler sets the handler for console output.

func (*Engine) SetGlobal

func (e *Engine) SetGlobal(name string, value interface{})

SetGlobal sets a global variable accessible from JavaScript.

type LogHandler

type LogHandler func(message string)

LogHandler is a function that handles log output from scripts.

type RequestSender

type RequestSender func(options map[string]interface{}) (map[string]interface{}, error)

RequestSender is a function that sends an HTTP request from within a script.

type SandboxedEngine

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

SandboxedEngine provides a secure JavaScript execution environment.

func NewSandboxedEngine

func NewSandboxedEngine() *SandboxedEngine

NewSandboxedEngine creates a new sandboxed JavaScript engine.

func (*SandboxedEngine) DisableEval

func (e *SandboxedEngine) DisableEval()

DisableEval disables eval() and Function constructor.

func (*SandboxedEngine) Execute

func (e *SandboxedEngine) Execute(ctx context.Context, script string) (interface{}, error)

Execute runs JavaScript code in the sandbox.

func (*SandboxedEngine) RegisterFunction

func (e *SandboxedEngine) RegisterFunction(name string, fn interface{})

RegisterFunction registers a Go function callable from JavaScript.

func (*SandboxedEngine) RegisterObject

func (e *SandboxedEngine) RegisterObject(name string, obj map[string]interface{})

RegisterObject registers a Go object as a JavaScript global.

func (*SandboxedEngine) SetConsoleHandler

func (e *SandboxedEngine) SetConsoleHandler(handler func(level, msg string))

SetConsoleHandler sets the handler for console output.

func (*SandboxedEngine) SetGlobal

func (e *SandboxedEngine) SetGlobal(name string, value interface{})

SetGlobal sets a global variable in the sandbox.

func (*SandboxedEngine) SetIterationLimit

func (e *SandboxedEngine) SetIterationLimit(limit int64)

SetIterationLimit sets the maximum number of loop iterations.

func (*SandboxedEngine) SetMemoryLimit

func (e *SandboxedEngine) SetMemoryLimit(limit int64)

SetMemoryLimit sets the memory limit (note: not strictly enforced by Goja).

type SandboxedScope

type SandboxedScope struct {
	*ScopeWithAssertions
	// contains filtered or unexported fields
}

SandboxedScope extends ScopeWithAssertions with sandbox protection.

func NewSandboxedScope

func NewSandboxedScope() *SandboxedScope

NewSandboxedScope creates a new scope with sandbox protection.

func (*SandboxedScope) DisableEval

func (s *SandboxedScope) DisableEval()

DisableEval disables eval in the sandbox.

func (*SandboxedScope) Execute

func (s *SandboxedScope) Execute(ctx context.Context, script string) (interface{}, error)

Execute runs a script in the sandboxed scope.

func (*SandboxedScope) SetIterationLimit

func (s *SandboxedScope) SetIterationLimit(limit int64)

SetIterationLimit sets the iteration limit for the sandbox.

func (*SandboxedScope) SetSandboxConsoleHandler

func (s *SandboxedScope) SetSandboxConsoleHandler(handler func(level, msg string))

SetSandboxConsoleHandler sets the console handler for the sandbox.

type Scope

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

Scope provides the execution context for scripts with the currier.* API.

func NewScope

func NewScope() *Scope

NewScope creates a new script execution scope.

func (*Scope) Clone

func (s *Scope) Clone() *Scope

Clone creates a copy of the scope.

func (*Scope) Engine

func (s *Scope) Engine() *Engine

Engine returns the underlying JavaScript engine.

func (*Scope) Execute

func (s *Scope) Execute(ctx context.Context, script string) (interface{}, error)

Execute runs a script in this scope.

func (*Scope) GetEnvironmentVariable

func (s *Scope) GetEnvironmentVariable(key string) string

GetEnvironmentVariable gets an environment variable.

func (*Scope) GetRequestBody

func (s *Scope) GetRequestBody() string

GetRequestBody gets the request body.

func (*Scope) GetRequestHeaders

func (s *Scope) GetRequestHeaders() map[string]string

GetRequestHeaders gets the request headers.

func (*Scope) GetRequestURL

func (s *Scope) GetRequestURL() string

GetRequestURL gets the request URL.

func (*Scope) GetVariable

func (s *Scope) GetVariable(key string) string

GetVariable gets a variable value.

func (*Scope) Reset

func (s *Scope) Reset()

Reset clears all scope data.

func (*Scope) SetEnvironmentName

func (s *Scope) SetEnvironmentName(name string)

SetEnvironmentName sets the environment name.

func (*Scope) SetEnvironmentVariable

func (s *Scope) SetEnvironmentVariable(key, value string)

SetEnvironmentVariable sets an environment variable.

func (*Scope) SetLogHandler

func (s *Scope) SetLogHandler(handler LogHandler)

SetLogHandler sets the handler for log output.

func (*Scope) SetRequestBody

func (s *Scope) SetRequestBody(body string)

SetRequestBody sets the request body.

func (*Scope) SetRequestHeaders

func (s *Scope) SetRequestHeaders(headers map[string]string)

SetRequestHeaders sets the request headers.

func (*Scope) SetRequestMethod

func (s *Scope) SetRequestMethod(method string)

SetRequestMethod sets the request method.

func (*Scope) SetRequestSender

func (s *Scope) SetRequestSender(sender RequestSender)

SetRequestSender sets the function for sending requests from scripts.

func (*Scope) SetRequestURL

func (s *Scope) SetRequestURL(url string)

SetRequestURL sets the request URL.

func (*Scope) SetResponseBody

func (s *Scope) SetResponseBody(body string)

SetResponseBody sets the response body.

func (*Scope) SetResponseHeaders

func (s *Scope) SetResponseHeaders(headers map[string]string)

SetResponseHeaders sets the response headers.

func (*Scope) SetResponseSize

func (s *Scope) SetResponseSize(size int64)

SetResponseSize sets the response size in bytes.

func (*Scope) SetResponseStatus

func (s *Scope) SetResponseStatus(status int)

SetResponseStatus sets the response status code.

func (*Scope) SetResponseStatusText

func (s *Scope) SetResponseStatusText(text string)

SetResponseStatusText sets the response status text.

func (*Scope) SetResponseTime

func (s *Scope) SetResponseTime(time int64)

SetResponseTime sets the response time in milliseconds.

func (*Scope) SetVariable

func (s *Scope) SetVariable(key, value string)

SetVariable sets a variable.

type ScopeWithAssertions

type ScopeWithAssertions struct {
	*Scope
	// contains filtered or unexported fields
}

ScopeWithAssertions extends Scope with test assertion capabilities.

func NewScopeWithAssertions

func NewScopeWithAssertions() *ScopeWithAssertions

NewScopeWithAssertions creates a new scope with assertion capabilities.

func (*ScopeWithAssertions) AllTestsPassed

func (s *ScopeWithAssertions) AllTestsPassed() bool

AllTestsPassed returns true if all tests passed.

func (*ScopeWithAssertions) ClearTestResults

func (s *ScopeWithAssertions) ClearTestResults()

ClearTestResults clears all test results.

func (*ScopeWithAssertions) Execute

func (s *ScopeWithAssertions) Execute(ctx context.Context, script string) (interface{}, error)

Execute runs a script in this scope with assertion support.

func (*ScopeWithAssertions) GetTestResults

func (s *ScopeWithAssertions) GetTestResults() []TestResult

GetTestResults returns all test results.

func (*ScopeWithAssertions) GetTestSummary

func (s *ScopeWithAssertions) GetTestSummary() TestSummary

GetTestSummary returns aggregate test statistics.

type TestResult

type TestResult struct {
	Name   string
	Passed bool
	Error  string
}

TestResult represents the result of a single test.

type TestSummary

type TestSummary struct {
	Total  int
	Passed int
	Failed int
}

TestSummary provides aggregate test statistics.

Jump to

Keyboard shortcuts

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