exec

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpected           = errors.New("unexpected")
	ErrSyntaxError_Case     = errors.New("syntax error: please use `case <testCaseName>`")
	ErrSyntaxError_TearDown = errors.New("syntax error: please use `tearDown`")
)
View Source
var (
	ErrSubCmdNotFound = errors.New("sub command not found")
)

Functions

func ExecCases

func ExecCases(t httptest.TestingT, code string) (err error)

Types

type Case

type Case struct {
	Name string
	Code string
}

一般测试案例框架都有选择性执行某个案例、多个案例共享 setUp、tearDown 这样的启动和终止代码。我们也可以考虑支持。设想如下:

#代码片段1
...

case testCase1
#代码片段2
...

case testCase2
#代码片段3
...

tearDown
#代码片段4
...

这段代码里面,“代码片段1” 将被认为是 setUp 代码,“代码片段4” 是 tearDown 代码,所有 testCase 开始前都会执行一遍“代码片段1”,退出前执行一遍“代码片段4”。每个 case 不用写 end 语句,遇到下一个 case 或者遇到 tearDown 就代表该 case 结束。

type Cases

type Cases struct {
	SetUp    string
	TearDown string
	Items    []Case
}

func ParseCases

func ParseCases(code string) (cases Cases, err error)

func (*Cases) Exec

func (p *Cases) Exec(ctx *httptest.Context, code string)

type Context

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

func New

func New() *Context

func (*Context) Cmd_auth

func (p *Context) Cmd_auth(ctx *httptest.Context, args *authArgs)

func (*Context) Cmd_binary

func (p *Context) Cmd_binary(ctx *httptest.Context, args *body1Args)

func (*Context) Cmd_body

func (p *Context) Cmd_body(ctx *httptest.Context, args *bodyArgs)

func (*Context) Cmd_bson

func (p *Context) Cmd_bson(ctx *httptest.Context, args *body1Args)

func (*Context) Cmd_clear

func (p *Context) Cmd_clear(ctx *httptest.Context, args *clearArgs)

func (*Context) Cmd_delete

func (p *Context) Cmd_delete(ctx *httptest.Context, args *req1Args)

func (*Context) Cmd_echo

func (p *Context) Cmd_echo(ctx *httptest.Context, args *printlnArgs)

func (*Context) Cmd_equal

func (p *Context) Cmd_equal(ctx *httptest.Context, args *equalArgs)

func (*Context) Cmd_equalSet

func (p *Context) Cmd_equalSet(ctx *httptest.Context, args *equalArgs)

func (*Context) Cmd_form

func (p *Context) Cmd_form(ctx *httptest.Context, args *body1Args)

func (*Context) Cmd_get

func (p *Context) Cmd_get(ctx *httptest.Context, args *req1Args)

func (*Context) Cmd_header

func (p *Context) Cmd_header(ctx *httptest.Context, args *headerArgs)

func (*Context) Cmd_host

func (p *Context) Cmd_host(ctx *httptest.Context, args *hostArgs)

func (*Context) Cmd_json

func (p *Context) Cmd_json(ctx *httptest.Context, args *body1Args)

func (*Context) Cmd_let

func (p *Context) Cmd_let(ctx *httptest.Context, args *letArgs)

func (*Context) Cmd_match

func (p *Context) Cmd_match(ctx *httptest.Context, args *matchArgs)

func (*Context) Cmd_post

func (p *Context) Cmd_post(ctx *httptest.Context, args *req1Args)

func (*Context) Cmd_println

func (p *Context) Cmd_println(ctx *httptest.Context, args *printlnArgs)

func (*Context) Cmd_put

func (p *Context) Cmd_put(ctx *httptest.Context, args *req1Args)

func (*Context) Cmd_req

func (p *Context) Cmd_req(ctx *httptest.Context, args *reqArgs)

func (*Context) Cmd_ret

func (p *Context) Cmd_ret(ctx *httptest.Context, args *retArgs)

func (*Context) Exec

func (p *Context) Exec(ctx *httptest.Context, code string)

func (*Context) GetRawCmd

func (p *Context) GetRawCmd() string

type IContext

type IContext interface {
	GetRawCmd() string
}

type IExternalContext

type IExternalContext interface {
	FindCmd(ctx IContext, cmd string) reflect.Value
}
var (
	External    IExternalContext
	ExternalSub IExternalContext
)

Jump to

Keyboard shortcuts

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