apitest

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

README

apitest

API test for Go.

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 (
	// 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

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

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

func OpenFile

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

OpenFile 打开文件

func RegisterTagName

func RegisterTagName(tagName string)

func XMLIndent

func XMLIndent(w io.Writer, v any)

Types

type APIError

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

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

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

Errors 获取错误

func (*AT) FakeRun

func (at *AT) FakeRun() *AT

Run 运行

func (*AT) GetResultExtractor

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

func (*AT) InsecureSkipVerify added in v0.3.0

func (at *AT) InsecureSkipVerify() *AT

func (*AT) MarkAuthHeader

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

func (*AT) Method

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

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

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

func (*AT) Resp

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

func (*AT) Result

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

Result 获取结果

func (*AT) ResultWrapper added in v0.4.0

func (at *AT) ResultWrapper(rw ResultWrapper) *AT

ResultWrapper 指定结果包装结构

func (*AT) Run

func (at *AT) Run() *AT

Run 运行

func (*AT) SetCert added in v0.3.0

func (at *AT) SetCert(caCertPath, certFile, keyFile string) *AT

func (*AT) SetCookies

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

SetCookies 设置cookies

func (*AT) SetFile

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

SetFile 设置文件

func (*AT) SetHeader

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

SetHeader 设置header

func (*AT) SetHost

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

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

SetScheme 设置scheme

func (*AT) SetStatus

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

func (*AT) Title

func (at *AT) Title() string

func (*AT) UseXMLFormat

func (at *AT) UseXMLFormat() *AT

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

func (*AT) UseXMLParamFormat

func (at *AT) UseXMLParamFormat() *AT

UseXMLParamFormat 设置参数格式为XML

func (*AT) UseXMLResultFormat

func (at *AT) UseXMLResultFormat() *AT

UseXMLResultFormat 设置结果格式为XML

func (*AT) WriteFile

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

WriteFile 写入markdown文件

type CatalogEntry

type CatalogEntry struct {
	Title  string
	Method string
	Path   string
}

type Example added in v0.12.0

type Example struct {
	Inputs      []Input
	Method      string
	Path        string
	Token       string
	Params      string
	ResultDivId string
}

type Input added in v0.12.0

type Input struct {
	Name        string
	Login       string
	Id          string
	Placeholder string
}
type Link struct {
	Url   string
	Title string
}

type PressureParam

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

PressureParam 压力测试参数

type ResultExtractor

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

type ResultWrapper added in v0.4.0

type ResultWrapper interface {
	WithData(data any)
}

type SimpleKind

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

type Status

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

func (Status) String

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