easytest

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 12 Imported by: 0

README

   ('-.      ('-.       .-')                  .-') _       ('-.     .-')     .-') _    
 _(  OO)    ( OO ).-.  ( OO ).               (  OO) )    _(  OO)   ( OO ).  (  OO) )   
(,------.   / . --. / (_)---\_)   ,--.   ,--./     '._  (,------. (_)---\_) /     '._  
 |  .---'   | \-.  \  /    _ |     \  `.'  / |'--...__)  |  .---' /    _ |  |'--...__) 
 |  |     .-'-'  |  | \  :` `.   .-')     /  '--.  .--'  |  |     \  :` `.  '--.  .--' 
(|  '--.   \| |_.'  |  '..`''.) (OO  \   /      |  |    (|  '--.   '..`''.)    |  |    
 |  .--'    |  .-.  | .-._)   \  |   /  /\_     |  |     |  .--'  .-._)   \    |  |    
 |  `---.   |  | |  | \       /  `-./  /.__)    |  |     |  `---. \       /    |  |    
 `------'   `--' `--'  `-----'     `--'         `--'     `------'  `-----'     `--'    
  

方便地EasyTest测试模板

Build Status codecov


特性

http接口测试

  • 🗂 http接口的集成测试,添加环境变量机制
  • 📦 postman接口文件支持

安装

$ wget -o bin/easytest https://github.com/wwqdrh/easytest/releases/download/v0.0.1/easytest-linux-amd64

$ chmod +x bin/easytest

$ bin/easytest -json api.json

使用手册

现在支持的语法列表

  • $res.$body.$json: 返回响应body的json格式
  • $env.a = 1: 设置环境变量
  • $env.token = $res.$body.$json.accessToken: 获取响应的accessToken并作为环境变量
  • @contain($res.$body.$str, "ok"): 判断响应体中是否包含ok字符串
  • $env.token: 返回环境变量中的token

示例

[
    {
        "name": "用户注册",
        "url": "http://127.0.0.1:8000/api/user/register",
        "method": "post",
        "body": "{\r\n    \"name\":\"ving\",\r\n    \"gender\":1,\r\n    \"mobile\": \"15212230311\",\r\n    \"password\": \"123456\"\r\n}\r\n",
        "content-type": "application/json",
        "expect": [
            "@contain($res.$body.$str, \"ok\")"
        ]
    },
    {
        "name": "用户登录",
        "url": "http://127.0.0.1:8000/api/user/login",
        "method": "post",
        "body": "{\"name\":\"ving\",\"gender\":1,\"mobile\": \"15212230311\",\"password\": \"123456\"}",
        "content-type": "application/json",
        "expect": [
            "@contain($res.$body.$str, \"ok\")"
        ],
        "event": [
            "$env.token = $res.$body.$json.accessToken"
        ]
    },
    {
        "name": "用户信息",
        "url": "http://127.0.0.1:8000/api/user/userinfo",
        "method": "post",
        "body": "{\r\n    \"name\":\"ving\",\r\n    \"gender\":1,\r\n    \"mobile\": \"15212230311\",\r\n    \"password\": \"123456\"\r\n}\r\n",
        "content-type": "application/json",
        "header": [
            "Authorization: bearer {{ token }}"
        ],
        "expect": [
            "@contain($res.$body.$str, \"ok\")"
        ]
    }
]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Value  string
	IsFile bool
}

type HTTPOpt

type HTTPOpt struct {
	Engine    http.Handler
	Handler   http.HandlerFunc
	Method    string
	Url       string
	Header    map[string]string
	Cookies   []*http.Cookie
	Body      io.Reader
	Query     map[string][]string
	JSON      map[string]interface{}
	MultiForm map[string]Field
	// contains filtered or unexported fields
}

type HTTPRes

type HTTPRes struct {
	Code    int
	Header  map[string][]string
	Body    string
	Cookies []*http.Cookie
}

func HTTPTest

func HTTPTest(opt *HTTPOpt) (HTTPRes, error)

func (*HTTPRes) GJson

func (r *HTTPRes) GJson(key string) gjson.Result

Directories

Path Synopsis
cmd
internal
Package internal is a generated GoMock package.
Package internal is a generated GoMock package.

Jump to

Keyboard shortcuts

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