xtest

package
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout       error = errors.New("js runtime execute timeout")
	ErrInvalidReturn error = errors.New("test.onResponse returns a invalid type")
)

Functions

This section is empty.

Types

type APICallFunc

type APICallFunc func() (data Response, err error)

接口调用函数回调,用于调用API并设置返回值等,在 Pre-Script 执行完之后调用 如果接口调用失败,返回Error data 必须是一个可以被 JSON marshall 的数据,比如 struct 、map 等

type GlobalStore

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

GlobalStore 用于测试用例在执行过程中设置全局变量从而在测试用例之间共享数据

func NewGlobalStore

func NewGlobalStore() *GlobalStore

func (*GlobalStore) Get

func (g *GlobalStore) Get(key string) (value interface{})

func (*GlobalStore) Set

func (g *GlobalStore) Set(key string, value interface{})

type Interpreter

type Interpreter interface {
	// 设置
	Execute(context context.Context, script TestScript, handler APICallFunc) (result TestResult)

	// 注册脚本函数
	RegisterFunc(name string, f interface{}) error
}

type InterpreterType

type InterpreterType string
const (
	InterpreterTypeJS InterpreterType = "javascript"
)

type JSInterpreter

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

func NewJSInterpreter

func NewJSInterpreter(gs *GlobalStore) *JSInterpreter

func (*JSInterpreter) Execute

func (j *JSInterpreter) Execute(ctx context.Context, script TestScript, handler APICallFunc) (result TestResult)

func (*JSInterpreter) RegisterFunc

func (j *JSInterpreter) RegisterFunc(name string, f interface{}) error

func (*JSInterpreter) Set

func (j *JSInterpreter) Set(name string, value interface{}) error

type Option

type Option func(t *XTest)

func WithGlobalStore

func WithGlobalStore(flag bool) Option

func WithInterpreter

func WithInterpreter(interpreterType InterpreterType) Option

type Response

type Response interface{}

接口响应值

type TestResult

type TestResult struct {
	Logs        map[string]string `json:"logs"`
	TimeCost    time.Duration     `json:"time_cost"`
	Error       error             `json:"error"`
	Success     bool              `json:"success"`
	RawResponse interface{}       `json:"raw_response"`
}

type TestScript

type TestScript struct {
	Source string
}

测试脚本

type XTest

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

func New

func New(options ...Option) *XTest

func (*XTest) Interpreter

func (t *XTest) Interpreter() Interpreter

func (*XTest) Run

func (t *XTest) Run(c context.Context, script TestScript, handler APICallFunc) (result TestResult)

Jump to

Keyboard shortcuts

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