Documentation ¶
Overview ¶
Package rest 简单的 API 测试库
Index ¶
- type Request
- type Response
- func (resp *Response) Body(val []byte, msg ...interface{}) *Response
- func (resp *Response) BodyEmpty(msg ...interface{}) *Response
- func (resp *Response) BodyNil(msg ...interface{}) *Response
- func (resp *Response) BodyNotEmpty(msg ...interface{}) *Response
- func (resp *Response) BodyNotNil(msg ...interface{}) *Response
- func (resp *Response) Fail(msg ...interface{}) *Response
- func (resp *Response) Header(key string, val string, msg ...interface{}) *Response
- func (resp *Response) JSONBody(val interface{}) *Response
- func (resp *Response) NotHeader(key string, val string, msg ...interface{}) *Response
- func (resp *Response) NotStatus(status int, msg ...interface{}) *Response
- func (resp *Response) ReadBody(w io.Writer) *Response
- func (resp *Response) Status(status int, msg ...interface{}) *Response
- func (resp *Response) StringBody(val string, msg ...interface{}) *Response
- func (resp *Response) Success(msg ...interface{}) *Response
- type Server
- func (srv *Server) Close()
- func (srv *Server) Delete(path string) *Request
- func (srv *Server) Get(path string) *Request
- func (srv *Server) NewRequest(method, path string) *Request
- func (srv *Server) Patch(path string, body []byte) *Request
- func (srv *Server) Post(path string, body []byte) *Request
- func (srv *Server) Put(path string, body []byte) *Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 请求的参数封装
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response 测试请求的返回结构
func (*Response) BodyNotEmpty ¶ added in v1.3.2
BodyNotEmpty 报文内容是否不为空
func (*Response) BodyNotNil ¶
BodyNotNil 报文内容是否不为 nil
func (*Response) NotStatus ¶
NotStatus 判断状态码是否与 status 不相等,若相等,则返回 msg 指定的消息
msg 可以为空,会返回一个默认的错误提示信息
func (*Response) StringBody ¶
StringBody 报文内容是否与 val 相等
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 测试服务
func (*Server) NewRequest ¶
NewRequest 获取一条请求的结果
method 表示请求方法 path 表示请求的路径,可以通过 {} 指定参数,比如:
r := NewRequest(http.MethodGet, "/users/{id}")
之后就可以使用 Params 指定 id 的具体值,达到复用的目的:
resp1 := r.Param("id", "1").Do() resp2 := r.Param("id", "2").Do()
Click to show internal directories.
Click to hide internal directories.