apitest

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package apitest Usage:

NewAT(xxx).
	SetParam(xxx).
	Debug().
	Run().
	EqualCode(xxx).
	Result(xxx).
	Equal(...).
	WriteFile(xxx).
	Err()

Index

Constants

This section is empty.

Variables

View Source
var (
	ATMockDebugProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "Debug"
		return
	}()
	ATMockEqualProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "Equal"
		return
	}()
	ATMockEqualCodeProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "EqualCode"
		return
	}()
	ATMockEqualThenProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "EqualThen"
		return
	}()
	ATMockErrProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "Err"
		return
	}()
	ATMockMonkeyRunProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "MonkeyRun"
		return
	}()
	ATMockNewProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "New"
		return
	}()
	ATMockPressureRunProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "PressureRun"
		return
	}()
	ATMockPressureRunBatchProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "PressureRunBatch"
		return
	}()
	ATMockResultProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "Result"
		return
	}()
	ATMockRunProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "Run"
		return
	}()
	ATMockSetCookiesProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "SetCookies"
		return
	}()
	ATMockSetHeaderProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "SetHeader"
		return
	}()
	ATMockSetParamProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "SetParam"
		return
	}()
	ATMockSetPortProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "SetPort"
		return
	}()
	ATMockWriteFileProxyContext = func() (pctx inject.ProxyContext) {
		pctx = aTMockCommonProxyContext
		pctx.MethodName = "WriteFile"
		return
	}()
)
View Source
var (
	// ErrNilParam 参数为nil
	ErrNilParam = errors.New("please input param, param is nil now")
)

Predefined error

Functions

func CookieMapToSlice

func CookieMapToSlice(cm map[string]string) []*http.Cookie

CookieMapToSlice map转为slice

func GinHandlerAPIDoc added in v0.13.0

func GinHandlerAPIDoc(doc *gin.RouterGroup, dir string, brand string)

GinHandlerAPIDoc 针对指定目录下的md接口文档,生成对应的html文件,并注册到gin路由上

func JSONIndent

func JSONIndent(w io.Writer, v any)

JSONIndent json格式化后输出

func MakeCatalog added in v0.13.0

func MakeCatalog(entries []CatalogEntry) (string, error)

func OpenFile

func OpenFile(file, title string) (*os.File, error)

OpenFile 打开文件

func RegisterProxyMethod added in v0.12.0

func RegisterProxyMethod(pctx inject.ProxyContext, cf inject.CtxFunc)

func RegisterTagName added in v0.13.1

func RegisterTagName(tagName string)

func XMLIndent added in v0.13.0

func XMLIndent(w io.Writer, v any)

Types

type APIError added in v0.13.0

type APIError interface {
	Code() string
	Msg() string
}

type AT

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

AT api test

func NewAT

func NewAT(
	path,
	method,
	comment string,
	h http.Header,
	cookies []*http.Cookie,
) *AT

NewAT 新建

func (*AT) CatalogEntry added in v0.13.0

func (at *AT) CatalogEntry() CatalogEntry

func (*AT) Debug

func (at *AT) Debug() *AT

Debug 开启调试模式

func (*AT) Equal

func (at *AT) Equal(args ...any) *AT

Equal 校验

func (*AT) EqualCode

func (at *AT) EqualCode(wantCode int) *AT

EqualCode 比较响应码

func (*AT) EqualThen

func (at *AT) EqualThen(f func(*AT) error, args ...any) *AT

EqualThen 相等之后

func (*AT) Err

func (at *AT) Err() error

func (*AT) Errors added in v0.13.0

func (at *AT) Errors(errs ...any) *AT

Errors 获取错误

func (*AT) FakeRun added in v0.8.0

func (at *AT) FakeRun() *AT

Run 运行

func (*AT) GetResultExtractor added in v0.24.0

func (at *AT) GetResultExtractor(format string) (re ResultExtractor, ok bool)

func (*AT) MarkAuthHeader added in v0.8.2

func (at *AT) MarkAuthHeader(authHeaderKey, authHeaderValue string) *AT

func (*AT) Method added in v0.13.0

func (at *AT) Method() string

func (*AT) MonkeyRun

func (at *AT) MonkeyRun() *AT

MonkeyRun 猴子运行

func (*AT) New

func (at *AT) New() *AT

New 克隆一个新的AT

func (*AT) Path added in v0.13.0

func (at *AT) Path() string

func (*AT) PressureRun

func (at *AT) PressureRun(n, c int) *AT

PressureRun 压力运行,n: 运行次数,c: 并发数

func (*AT) PressureRunBatch

func (at *AT) PressureRunBatch(param []PressureParam) *AT

PressureRunBatch 批量压力运行

func (*AT) RegisterResultExtractor added in v0.24.0

func (at *AT) RegisterResultExtractor(format string, re ResultExtractor) *AT

func (*AT) Resp added in v0.16.0

func (at *AT) Resp() *http.Response

func (*AT) Result

func (at *AT) Result(r any) *AT

Result 获取结果

func (*AT) Run

func (at *AT) Run() *AT

Run 运行

func (*AT) SetCookies

func (at *AT) SetCookies(cookies []*http.Cookie) *AT

SetCookies 设置cookies

func (*AT) SetFile added in v0.13.0

func (at *AT) SetFile(file string) *AT

SetFile 设置文件

func (*AT) SetHeader

func (at *AT) SetHeader(header http.Header) *AT

SetHeader 设置header

func (*AT) SetHost added in v0.19.0

func (at *AT) SetHost(host string) *AT

SetHost 设置host

func (*AT) SetParam

func (at *AT) SetParam(param any) *AT

SetParam 设置参数

func (*AT) SetPort

func (at *AT) SetPort(port string) *AT

SetPort 设置端口,如":8080"

func (*AT) SetScheme added in v0.19.0

func (at *AT) SetScheme(scheme string) *AT

SetScheme 设置scheme

func (*AT) SetStatus added in v0.21.0

func (at *AT) SetStatus(status Status) *AT

func (*AT) Title added in v0.13.0

func (at *AT) Title() string

func (*AT) UseXMLFormat added in v0.13.0

func (at *AT) UseXMLFormat() *AT

UseXMLFormat 设置参数和结果格式为XML

func (*AT) UseXMLParamFormat added in v0.13.0

func (at *AT) UseXMLParamFormat() *AT

UseXMLParamFormat 设置参数格式为XML

func (*AT) UseXMLResultFormat added in v0.13.0

func (at *AT) UseXMLResultFormat() *AT

UseXMLResultFormat 设置结果格式为XML

func (*AT) WriteFile

func (at *AT) WriteFile(w io.Writer) *AT

WriteFile 写入markdown文件

type ATMock added in v0.5.0

type ATMock struct {
	DebugFunc func() *AT

	EqualFunc func(args ...any) *AT

	EqualCodeFunc func(wantCode int) *AT

	EqualThenFunc func(f func(*AT) error, args ...any) *AT

	ErrFunc func() error

	MonkeyRunFunc func() *AT

	NewFunc func() *AT

	PressureRunFunc func(n int, c int) *AT

	PressureRunBatchFunc func(param []PressureParam) *AT

	ResultFunc func(r any) *AT

	RunFunc func() *AT

	SetCookiesFunc func(cookies []*http.Cookie) *AT

	SetHeaderFunc func(header http.Header) *AT

	SetParamFunc func(param any) *AT

	SetPortFunc func(port string) *AT

	WriteFileFunc func(w io.Writer) *AT
}

func (*ATMock) Debug added in v0.5.0

func (mockRecv *ATMock) Debug() *AT

func (*ATMock) Equal added in v0.5.0

func (mockRecv *ATMock) Equal(args ...any) *AT

func (*ATMock) EqualCode added in v0.5.0

func (mockRecv *ATMock) EqualCode(wantCode int) *AT

func (*ATMock) EqualThen added in v0.5.0

func (mockRecv *ATMock) EqualThen(f func(*AT) error, args ...any) *AT

func (*ATMock) Err added in v0.5.0

func (mockRecv *ATMock) Err() error

func (*ATMock) MonkeyRun added in v0.5.0

func (mockRecv *ATMock) MonkeyRun() *AT

func (*ATMock) New added in v0.5.0

func (mockRecv *ATMock) New() *AT

func (*ATMock) PressureRun added in v0.5.0

func (mockRecv *ATMock) PressureRun(n int, c int) *AT

func (*ATMock) PressureRunBatch added in v0.5.0

func (mockRecv *ATMock) PressureRunBatch(param []PressureParam) *AT

func (*ATMock) Result added in v0.5.0

func (mockRecv *ATMock) Result(r any) *AT

func (*ATMock) Run added in v0.5.0

func (mockRecv *ATMock) Run() *AT

func (*ATMock) SetCookies added in v0.5.0

func (mockRecv *ATMock) SetCookies(cookies []*http.Cookie) *AT

func (*ATMock) SetHeader added in v0.5.0

func (mockRecv *ATMock) SetHeader(header http.Header) *AT

func (*ATMock) SetParam added in v0.5.0

func (mockRecv *ATMock) SetParam(param any) *AT

func (*ATMock) SetPort added in v0.5.0

func (mockRecv *ATMock) SetPort(port string) *AT

func (*ATMock) WriteFile added in v0.5.0

func (mockRecv *ATMock) WriteFile(w io.Writer) *AT

type CatalogEntry added in v0.13.0

type CatalogEntry struct {
	Title  string
	Method string
	Path   string
}

type IAT added in v0.5.0

type IAT interface {
	Debug() *AT
	Equal(args ...any) *AT
	EqualCode(wantCode int) *AT
	EqualThen(f func(*AT) error, args ...any) *AT
	Err() error
	MonkeyRun() *AT
	New() *AT
	PressureRun(n int, c int) *AT
	PressureRunBatch(param []PressureParam) *AT
	Result(r any) *AT
	Run() *AT
	SetCookies(cookies []*http.Cookie) *AT
	SetHeader(header http.Header) *AT
	SetParam(param any) *AT
	SetPort(port string) *AT
	WriteFile(w io.Writer) *AT
}
type Link struct {
	Url   string
	Title string
}

type PressureParam

type PressureParam struct {
	N int // 运行次数
	C int // 并发数
}

PressureParam 压力测试参数

type ResultExtractor added in v0.24.0

type ResultExtractor func(data []byte, r any) error

type SimpleKind added in v0.12.0

type SimpleKind interface {
	~int | ~int16 | ~int32 | ~int64 | ~int8 |
		~uint | ~uint16 | ~uint32 | ~uint64 | ~uint8 |
		~string |
		~bool |
		~float32 | ~float64
}

type Status added in v0.21.0

type Status int
const (
	StatusNone           Status = 0
	StatusInDesign       Status = 1 // 设计中
	StatusNotImplemented Status = 2 // 未实现
	StatusImplementation Status = 3 // 实现中
	StatusImplemented    Status = 4 // 已实现
)

func (Status) String added in v0.21.0

func (s Status) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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