httpvf

package module
v0.0.0-...-1b46f5d Latest Latest
Warning

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

Go to latest
Published: May 26, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

README

httpvf

http REST API verify

get

go get github.com/toukii/httpvf/vf

example

vf.yml:

-
  url: http://upload.daoapp.io/topic
  method: POST
  header:
    Content-Type: "application/x-www-form-urlencoded"
  body: "title=topic001&content=content001"
  resp:
    code: 200
    cost: 900
-
  url: http://upload.daoapp.io/loadfile/topic001
  method: GET
  resp:
    code: 200
    cost: 80
    body: content001
-
  url: http://upload.daoapp.io/uploadform/
  method: POST
  filename : vf.yml
  resp:
    code: 200
    cost: 10

verify:

vf -v vf.yml

请求

  • url: [请求地址]

  • method: [请求方法]

  • body: [请求body],可以将请求写在文件中,body的写法:

body: "@[filename]"
  • n: [请求个数]

  • interval: [请求间隔]

  • runtine: [请求并发数]

  • upload: [web前段传入的文件名(input name)]@[上传文件名]

  • header: 请求的header参数,map结构

header:
   Content-Type: "application/x-www-form-urlencoded"
  • param: GET 请求的参数,map结构
param:
  name: toukii
  position: dev-ops
  • then: [下一步请求]
then:
  - url: https://github.com/toukii
  - url: https://github.com/toukii/httpvf
  • sync: [下一步请求的同步方式,仅约束下一级的请求]
sync: true

例如:

url: http://gocn.io
sync: true
then:
  - url: https://github.com/toukii
  - url: https://github.com/toukii/httpvf

完成gocn.io的请求之后,同步依次完成两个子请求。


验证响应

  • code: [响应码]

  • cost: [响应时间,单位ms]

  • body: [直接验证内容]

  • regex: [正则表达式]

json
  • 路径以","分割

  • 路径若有纯数字,为数字加上""

  • 数组下标从0开始,直接写数字

例如,返回的json内容如下:

[
    {
        "Map": {
            "1": "hello"
        },
        "Message": "This is toukii,r1",
        "Cost": 0.315
    }
]

验证hello的写法为:

json: 
  '0,Map,"1"': hello

Documentation

Index

Constants

View Source
const (
	INFO       = "INFO"
	WARN       = "WARN"
	ERROR      = "ERROR"
	FATAL      = "FATAL"
	CONCLUSION = "CONCLUSION"
)
View Source
const (
	GET  = "GET"
	POST = "POST"
)

Variables

View Source
var (
	MsgLevel = INFO // msg 的级别
)

Functions

func Test

func Test()

func Verify

func Verify(vf string)

Types

type Log

type Log struct {
	Level string
	Out   string
}

type Msg

type Msg struct {
	Req           *Req
	InfoLog       []*Log
	WarnLog       []*Log
	ErrorLog      []*Log
	FatalLog      []*Log
	ConclusionLog []*Log
}

func (*Msg) Append

func (m *Msg) Append(level, out string)

func (*Msg) AppendLog

func (m *Msg) AppendLog(log *Log)

func (*Msg) AppendLogs

func (m *Msg) AppendLogs(logs []*Log)

func (Msg) Logs

func (m Msg) Logs() []*Log

func (Msg) String

func (m Msg) String() string

type Req

type Req struct {
	N        int
	URL      string
	Method   string
	Header   map[string]string
	Param    map[string]string
	Body     string
	Resp     Resp
	Upload   string
	Interval int
	Runtine  int
	Timeout  int64
	Then     []*Req
	Sync     bool // 根请求(第一个请求)为异步模式,默认同一层请求为异步模式
}

func ReqFmt

func ReqFmt(in []byte) (*Req, error)

func Reqs

func Reqs(filename string) (reqs []*Req, err error)

func (*Req) Do

func (req *Req) Do() ([]byte, error)

func (Req) MapKey

func (req Req) MapKey() string

func (*Req) Prapare

func (req *Req) Prapare()

type Resp

type Resp struct {
	Code     int
	Cost     int
	RealCost int
	Body     string
	Regex    string // regex body
	Json     map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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