hrp

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

README

hrp (HttpRunner+)

Go Reference Github Actions codecov Go Report Card FOSSA Status

hrp aims to be a one-stop solution for HTTP(S) testing, covering API testing, load testing and digital experience monitoring (DEM).

Key Features

flow chart

  • Full support for HTTP(S) requests, more protocols are also in the plan.
  • Testcases can be described in multiple formats, YAML/JSON/Golang, and they are interchangeable.
  • With HAR support, you can use Charles/Fiddler/Chrome/etc as a script recording generator.
  • Supports variables/extract/validate/hooks mechanisms to create extremely complex test scenarios.
  • Built-in integration of rich functions, and you can also use hashicorp/plugin or go plugin to create and call custom functions.
  • Inherit all powerful features of Boomer and locust, you can run load test without extra work.
  • Using it as a CLI tool or a library are both supported.

See CHANGELOG.

Quick Start

use as CLI tool

You can install hrp with one shell command, which will download the latest version's released binary and install to the current system.

# install via curl
$ bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)"
# install via wget
$ bash -c "$(wget https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh -O -)"

If you are a golang developer, you can also install hrp with go get.

$ go get -u github.com/httprunner/hrp/cli/hrp

Since installed, you will get a hrp command with multiple sub-commands.

$ hrp -h

██╗  ██╗████████╗████████╗██████╗ ██████╗ ██╗   ██╗███╗   ██╗███╗   ██╗███████╗██████╗
██║  ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║   ██║████╗  ██║████╗  ██║██╔════╝██╔══██╗
███████║   ██║      ██║   ██████╔╝██████╔╝██║   ██║██╔██╗ ██║██╔██╗ ██║█████╗  ██████╔╝
██╔══██║   ██║      ██║   ██╔═══╝ ██╔══██╗██║   ██║██║╚██╗██║██║╚██╗██║██╔══╝  ██╔══██╗
██║  ██║   ██║      ██║   ██║     ██║  ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║  ██║
╚═╝  ╚═╝   ╚═╝      ╚═╝   ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝

hrp (HttpRunner+) aims to be a one-stop solution for HTTP(S) testing, covering API testing,
load testing and digital experience monitoring (DEM). Enjoy! ✨ 🚀 ✨

License: Apache-2.0
Website: https://httprunner.com
Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk

Usage:
  hrp [command]

Available Commands:
  boom         run load test with boomer
  completion   generate the autocompletion script for the specified shell
  har2case     convert HAR to json/yaml testcase files
  help         Help about any command
  run          run API test
  startproject create a scaffold project

Flags:
  -h, --help               help for hrp
      --log-json           set log to json format
  -l, --log-level string   set log level (default "INFO")
  -v, --version            version for hrp

Use "hrp [command] --help" for more information about a command.

You can use hrp run command to run HttpRunner JSON/YAML testcases. The following is an example running examples/demo.json

$ hrp run examples/demo.json
5:21PM INF Set log to color console other than JSON format.
5:21PM ??? Set log level
5:21PM INF [init] SetDebug debug=true
5:21PM INF [init] SetFailfast failfast=true
5:21PM INF [init] Reset session variables
5:21PM INF load json testcase path=/Users/debugtalk/MyProjects/HttpRunner-dev/hrp/examples/demo.json
5:21PM INF call function success arguments=[5] funcName=gen_random_string output=A65rg
5:21PM INF call function success arguments=[12.3,3.45] funcName=max output=12.3
5:21PM INF run testcase start testcase="demo with complex mechanisms"
5:21PM INF transaction name=tran1 type=start
5:21PM INF run step start step="get with params"
5:21PM INF call function success arguments=[12.3,34.5] funcName=max output=34.5
-------------------- request --------------------
GET /get?foo1=A65rg&foo2=34.5 HTTP/1.1
Host: postman-echo.com
User-Agent: HttpRunnerPlus


==================== response ===================
HTTP/1.1 200 OK
Content-Length: 304
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 23 Dec 2021 09:21:30 GMT
Etag: W/"130-t7qE4M7C+OQ0jGdRWkr2R3gjq+w"
Set-Cookie: sails.sid=s%3AAiqfRgMtWKG3oOQnXJOxRD8xk58rtAW6.eD%2BBo7FBnA82XLsLFiadeg6OcuD2zHSTyhv2l%2FDVuCk; Path=/; HttpOnly
Vary: Accept-Encoding

{"args":{"foo1":"A65rg","foo2":"34.5"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-61c43f9a-7c855775053963a4284ba464","user-agent":"HttpRunnerPlus","accept-encoding":"gzip"},"url":"https://postman-echo.com/get?foo1=A65rg&foo2=34.5"}
--------------------------------------------------
5:21PM INF extract value from=body.args.foo1 value=A65rg
5:21PM INF set variable value=A65rg variable=varFoo1
5:21PM INF validate status_code assertMethod=equals checkValue=200 expectValue=200 result=true
5:21PM INF validate headers."Content-Type" assertMethod=startswith checkValue="application/json; charset=utf-8" expectValue=application/json result=true
5:21PM INF validate body.args.foo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
5:21PM INF validate $varFoo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
5:21PM INF validate body.args.foo2 assertMethod=equals checkValue=34.5 expectValue=34.5 result=true
5:21PM INF run step end exportVars={"varFoo1":"A65rg"} step="get with params" success=true
5:21PM INF transaction name=tran1 type=end
5:21PM INF transaction elapsed=1021.174113 name=tran1
5:21PM INF run step start step="post json data"
5:21PM INF call function success arguments=[12.3,3.45] funcName=max output=12.3
-------------------- request --------------------
POST /post HTTP/1.1
Host: postman-echo.com
Content-Type: application/json; charset=UTF-8

{"foo1":"A65rg","foo2":12.3}
==================== response ===================
HTTP/1.1 200 OK
Content-Length: 424
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 23 Dec 2021 09:21:30 GMT
Etag: W/"1a8-IhWXQxTXlxmnbqdRh+oBPRTLsOU"
Set-Cookie: sails.sid=s%3AzXIPVMKipoISZG0Zj4tX73vKDbIdFtzZ.xD50I4UMHUERmcgWfp64f0a8g%2BT9YIUf0Fi1l5bXbQA; Path=/; HttpOnly
Vary: Accept-Encoding

{"args":{},"data":{"foo1":"A65rg","foo2":12.3},"files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-61c43f9a-78aab84a36a753ea6b5dd0f7","content-length":"28","user-agent":"Go-http-client/1.1","content-type":"application/json; charset=UTF-8","accept-encoding":"gzip"},"json":{"foo1":"A65rg","foo2":12.3},"url":"https://postman-echo.com/post"}
--------------------------------------------------
5:21PM INF validate status_code assertMethod=equals checkValue=200 expectValue=200 result=true
5:21PM INF validate body.json.foo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
5:21PM INF validate body.json.foo2 assertMethod=equals checkValue=12.3 expectValue=12.3 result=true
5:21PM INF run step end exportVars=null step="post json data" success=true
5:21PM INF run step start step="post form data"
5:21PM INF call function success arguments=[12.3,3.45] funcName=max output=12.3
-------------------- request --------------------
POST /post HTTP/1.1
Host: postman-echo.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8

foo1=A65rg&foo2=12.3
==================== response ===================
HTTP/1.1 200 OK
Content-Length: 445
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 23 Dec 2021 09:21:30 GMT
Etag: W/"1bd-g4G7WmMU7EzJYzPTYgqX67Ug9iE"
Set-Cookie: sails.sid=s%3Al3gcdxEQug7ddxPlA2Kfxvm7d_z9ImEt.4IQI1SVX5xuTefX0N0UvJPQxVvA1SAMm7ztHESkHXsY; Path=/; HttpOnly
Vary: Accept-Encoding

{"args":{},"data":"","files":{},"form":{"foo1":"A65rg","foo2":"12.3"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-61c43f9a-6458626c64b04fd60245714b","content-length":"20","user-agent":"Go-http-client/1.1","content-type":"application/x-www-form-urlencoded; charset=UTF-8","accept-encoding":"gzip"},"json":{"foo1":"A65rg","foo2":"12.3"},"url":"https://postman-echo.com/post"}
--------------------------------------------------
5:21PM INF validate status_code assertMethod=equals checkValue=200 expectValue=200 result=true
5:21PM INF validate body.form.foo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
5:21PM INF validate body.form.foo2 assertMethod=equals checkValue=12.3 expectValue=12.3 result=true
5:21PM INF run step end exportVars=null step="post form data" success=true
5:21PM INF run testcase end testcase="demo with complex mechanisms"
use as library

Beside using hrp as a CLI tool, you can also use it as golang library.

$ go get -u github.com/httprunner/hrp

This is an example of HttpRunner+ testcase. You can find more in the examples directory.

demo
import (
    "testing"

    "github.com/httprunner/hrp"
)

func TestCaseDemo(t *testing.T) {
    demoTestCase := &hrp.TestCase{
        Config: hrp.NewConfig("demo with complex mechanisms").
            SetBaseURL("https://postman-echo.com").
            WithVariables(map[string]interface{}{ // global level variables
                "n":       5,
                "a":       12.3,
                "b":       3.45,
                "varFoo1": "${gen_random_string($n)}",
                "varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
            }),
        TestSteps: []hrp.IStep{
            hrp.NewStep("transaction 1 start").StartTransaction("tran1"), // start transaction
            hrp.NewStep("get with params").
                WithVariables(map[string]interface{}{ // step level variables
                    "n":       3,                // inherit config level variables if not set in step level, a/varFoo1
                    "b":       34.5,             // override config level variable if existed, n/b/varFoo2
                    "varFoo2": "${max($a, $b)}", // 34.5; override variable b and eval again
                }).
                GET("/get").
                WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params
                WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).             // request with headers
                Extract().
                WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath
                Validate().
                AssertEqual("status_code", 200, "check response status code").        // validate response status code
                AssertStartsWith("headers.\"Content-Type\"", "application/json", ""). // validate response header
                AssertLengthEqual("body.args.foo1", 5, "check args foo1").            // validate response body with jmespath
                AssertLengthEqual("$varFoo1", 5, "check args foo1").                  // assert with extracted variable from current step
                AssertEqual("body.args.foo2", "34.5", "check args foo2"),             // notice: request params value will be converted to string
            hrp.NewStep("transaction 1 end").EndTransaction("tran1"), // end transaction
            hrp.NewStep("post json data").
                POST("/post").
                WithBody(map[string]interface{}{
                    "foo1": "$varFoo1",       // reference former extracted variable
                    "foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
                }).
                Validate().
                AssertEqual("status_code", 200, "check status code").
                AssertLengthEqual("body.json.foo1", 5, "check args foo1").
                AssertEqual("body.json.foo2", 12.3, "check args foo2"),
            hrp.NewStep("post form data").
                POST("/post").
                WithHeaders(map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}).
                WithBody(map[string]interface{}{
                    "foo1": "$varFoo1",       // reference former extracted variable
                    "foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
                }).
                Validate().
                AssertEqual("status_code", 200, "check status code").
                AssertLengthEqual("body.form.foo1", 5, "check args foo1").
                AssertEqual("body.form.foo2", "12.3", "check args foo2"), // form data will be converted to string
        },
    }

    err := hrp.NewRunner(nil).Run(demoTestCase) // hrp.Run(demoTestCase)
    if err != nil {
        t.Fatalf("run testcase error: %v", err)
    }
}

Subscribe

关注 HttpRunner 的微信公众号,第一时间获得最新资讯。

HttpRunner

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedFileExt = fmt.Errorf("unsupported testcase file extension")

Functions

func Run

func Run(testcases ...ITestCase) error

Run starts to run API test with default configs.

Types

type HRPBoomer added in v0.4.0

type HRPBoomer struct {
	*boomer.Boomer
	// contains filtered or unexported fields
}

func NewBoomer added in v0.3.0

func NewBoomer(spawnCount int, spawnRate float64) *HRPBoomer

func (*HRPBoomer) Quit added in v0.5.2

func (b *HRPBoomer) Quit()

func (*HRPBoomer) Run added in v0.4.0

func (b *HRPBoomer) Run(testcases ...ITestCase)

Run starts to run load test for one or multiple testcases.

func (*HRPBoomer) SetDebug added in v0.4.0

func (b *HRPBoomer) SetDebug(debug bool) *HRPBoomer

SetDebug configures whether to log HTTP request and response content.

type HRPRunner added in v0.4.0

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

func NewRunner

func NewRunner(t *testing.T) *HRPRunner

NewRunner constructs a new runner instance.

func (*HRPRunner) Run added in v0.4.0

func (r *HRPRunner) Run(testcases ...ITestCase) error

Run starts to execute one or multiple testcases.

func (*HRPRunner) SetDebug added in v0.4.0

func (r *HRPRunner) SetDebug(debug bool) *HRPRunner

SetDebug configures whether to log HTTP request and response content.

func (*HRPRunner) SetFailfast added in v0.4.0

func (r *HRPRunner) SetFailfast(failfast bool) *HRPRunner

SetFailfast configures whether to stop running when one step fails.

func (*HRPRunner) SetProxyUrl added in v0.4.0

func (r *HRPRunner) SetProxyUrl(proxyUrl string) *HRPRunner

SetProxyUrl configures the proxy URL, which is usually used to capture HTTP packets for debugging.

type IStep

type IStep interface {
	Name() string
	Type() string
	ToStruct() *TStep
}

IStep represents interface for all types for teststeps, includes: StepRequest, StepRequestWithOptionalArgs, StepRequestValidation, StepRequestExtraction, StepTestCaseWithOptionalArgs, StepTransaction, StepRendezvous.

type ITestCase

type ITestCase interface {
	ToTestCase() (*TestCase, error)
	ToTCase() (*TCase, error)
}

ITestCase represents interface for testcases, includes TestCase and TestCasePath.

type Iterator added in v0.4.0

type Iterator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Iterator) HasNext added in v0.4.0

func (iter *Iterator) HasNext() bool

func (*Iterator) Next added in v0.4.0

func (iter *Iterator) Next() (value map[string]interface{})

type Rendezvous added in v0.3.0

type Rendezvous struct {
	Name    string  `json:"name" yaml:"name"`                           // required
	Percent float32 `json:"percent,omitempty" yaml:"percent,omitempty"` // default to 1(100%)
	Number  int64   `json:"number,omitempty" yaml:"number,omitempty"`
	Timeout int64   `json:"timeout,omitempty" yaml:"timeout,omitempty"` // milliseconds
}

type Request added in v0.2.2

type Request struct {
	Method         string                 `json:"method" yaml:"method"` // required
	URL            string                 `json:"url" yaml:"url"`       // required
	Params         map[string]interface{} `json:"params,omitempty" yaml:"params,omitempty"`
	Headers        map[string]string      `json:"headers,omitempty" yaml:"headers,omitempty"`
	Cookies        map[string]string      `json:"cookies,omitempty" yaml:"cookies,omitempty"`
	Body           interface{}            `json:"body,omitempty" yaml:"body,omitempty"`
	Timeout        float32                `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	AllowRedirects bool                   `json:"allow_redirects,omitempty" yaml:"allow_redirects,omitempty"`
	Verify         bool                   `json:"verify,omitempty" yaml:"verify,omitempty"`
}

Request represents HTTP request data structure. This is used for teststep.

type StepRendezvous added in v0.3.0

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

StepRendezvous implements IStep interface.

func (*StepRendezvous) Name added in v0.3.0

func (s *StepRendezvous) Name() string

func (*StepRendezvous) ToStruct added in v0.3.0

func (s *StepRendezvous) ToStruct() *TStep

func (*StepRendezvous) Type added in v0.3.0

func (s *StepRendezvous) Type() string

type StepRequest added in v0.3.0

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

func NewStep added in v0.2.2

func NewStep(name string) *StepRequest

NewStep returns a new constructed teststep with specified step name.

func (*StepRequest) CallRefCase added in v0.3.0

func (s *StepRequest) CallRefCase(tc *TestCase) *StepTestCaseWithOptionalArgs

CallRefCase calls a referenced testcase.

func (*StepRequest) DELETE added in v0.3.0

DELETE makes a HTTP DELETE request.

func (*StepRequest) EndTransaction added in v0.3.0

func (s *StepRequest) EndTransaction(name string) *StepTransaction

EndTransaction ends a transaction.

func (*StepRequest) GET added in v0.3.0

GET makes a HTTP GET request.

func (*StepRequest) HEAD added in v0.3.0

HEAD makes a HTTP HEAD request.

func (*StepRequest) OPTIONS added in v0.3.0

OPTIONS makes a HTTP OPTIONS request.

func (*StepRequest) PATCH added in v0.3.0

PATCH makes a HTTP PATCH request.

func (*StepRequest) POST added in v0.3.0

POST makes a HTTP POST request.

func (*StepRequest) PUT added in v0.3.0

PUT makes a HTTP PUT request.

func (*StepRequest) SetupHook added in v0.3.0

func (s *StepRequest) SetupHook(hook string) *StepRequest

SetupHook adds a setup hook for current teststep.

func (*StepRequest) StartTransaction added in v0.3.0

func (s *StepRequest) StartTransaction(name string) *StepTransaction

StartTransaction starts a transaction.

func (*StepRequest) WithVariables added in v0.3.0

func (s *StepRequest) WithVariables(variables map[string]interface{}) *StepRequest

WithVariables sets variables for current teststep.

type StepRequestExtraction added in v0.3.0

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

StepRequestExtraction implements IStep interface.

func (*StepRequestExtraction) Name added in v0.3.0

func (s *StepRequestExtraction) Name() string

func (*StepRequestExtraction) ToStruct added in v0.3.0

func (s *StepRequestExtraction) ToStruct() *TStep

func (*StepRequestExtraction) Type added in v0.3.0

func (s *StepRequestExtraction) Type() string

func (*StepRequestExtraction) Validate added in v0.3.0

Validate switches to step validation.

func (*StepRequestExtraction) WithJmesPath added in v0.3.0

func (s *StepRequestExtraction) WithJmesPath(jmesPath string, varName string) *StepRequestExtraction

WithJmesPath sets the JMESPath expression to extract from the response.

type StepRequestValidation added in v0.3.0

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

StepRequestValidation implements IStep interface.

func (*StepRequestValidation) AssertContainedBy added in v0.4.0

func (s *StepRequestValidation) AssertContainedBy(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertContains added in v0.4.0

func (s *StepRequestValidation) AssertContains(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertEndsWith added in v0.3.0

func (s *StepRequestValidation) AssertEndsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertEqual added in v0.3.0

func (s *StepRequestValidation) AssertEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertGreater added in v0.4.0

func (s *StepRequestValidation) AssertGreater(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertGreaterOrEqual added in v0.4.0

func (s *StepRequestValidation) AssertGreaterOrEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthEqual added in v0.3.0

func (s *StepRequestValidation) AssertLengthEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthGreaterOrEquals added in v0.4.0

func (s *StepRequestValidation) AssertLengthGreaterOrEquals(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthGreaterThan added in v0.4.0

func (s *StepRequestValidation) AssertLengthGreaterThan(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthLessOrEquals added in v0.4.0

func (s *StepRequestValidation) AssertLengthLessOrEquals(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthLessThan added in v0.4.0

func (s *StepRequestValidation) AssertLengthLessThan(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLess added in v0.4.0

func (s *StepRequestValidation) AssertLess(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLessOrEqual added in v0.4.0

func (s *StepRequestValidation) AssertLessOrEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertNotEqual added in v0.4.0

func (s *StepRequestValidation) AssertNotEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertRegexp added in v0.4.0

func (s *StepRequestValidation) AssertRegexp(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertStartsWith added in v0.3.0

func (s *StepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertStringEqual added in v0.4.0

func (s *StepRequestValidation) AssertStringEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertTypeMatch added in v0.4.0

func (s *StepRequestValidation) AssertTypeMatch(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) Name added in v0.3.0

func (s *StepRequestValidation) Name() string

func (*StepRequestValidation) ToStruct added in v0.3.0

func (s *StepRequestValidation) ToStruct() *TStep

func (*StepRequestValidation) Type added in v0.3.0

func (s *StepRequestValidation) Type() string

type StepRequestWithOptionalArgs added in v0.3.0

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

StepRequestWithOptionalArgs implements IStep interface.

func (*StepRequestWithOptionalArgs) Extract added in v0.3.0

Extract switches to step extraction.

func (*StepRequestWithOptionalArgs) Name added in v0.3.0

func (*StepRequestWithOptionalArgs) SetAllowRedirects added in v0.3.0

func (s *StepRequestWithOptionalArgs) SetAllowRedirects(allowRedirects bool) *StepRequestWithOptionalArgs

SetAllowRedirects sets whether to allow redirects for current HTTP request.

func (*StepRequestWithOptionalArgs) SetAuth added in v0.3.0

SetAuth sets auth for current HTTP request.

func (*StepRequestWithOptionalArgs) SetProxies added in v0.3.0

SetProxies sets proxies for current HTTP request.

func (*StepRequestWithOptionalArgs) SetTimeout added in v0.3.0

SetTimeout sets timeout for current HTTP request.

func (*StepRequestWithOptionalArgs) SetVerify added in v0.3.0

SetVerify sets whether to verify SSL for current HTTP request.

func (*StepRequestWithOptionalArgs) TeardownHook added in v0.3.0

TeardownHook adds a teardown hook for current teststep.

func (*StepRequestWithOptionalArgs) ToStruct added in v0.3.0

func (s *StepRequestWithOptionalArgs) ToStruct() *TStep

func (*StepRequestWithOptionalArgs) Type added in v0.3.0

func (*StepRequestWithOptionalArgs) Validate added in v0.3.0

Validate switches to step validation.

func (*StepRequestWithOptionalArgs) WithBody added in v0.3.0

func (s *StepRequestWithOptionalArgs) WithBody(body interface{}) *StepRequestWithOptionalArgs

WithBody sets HTTP request body for current step.

func (*StepRequestWithOptionalArgs) WithCookies added in v0.3.0

WithCookies sets HTTP request cookies for current step.

func (*StepRequestWithOptionalArgs) WithHeaders added in v0.3.0

WithHeaders sets HTTP request headers for current step.

func (*StepRequestWithOptionalArgs) WithParams added in v0.3.0

func (s *StepRequestWithOptionalArgs) WithParams(params map[string]interface{}) *StepRequestWithOptionalArgs

WithParams sets HTTP request params for current step.

type StepTestCaseWithOptionalArgs added in v0.3.0

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

StepTestCaseWithOptionalArgs implements IStep interface.

func (*StepTestCaseWithOptionalArgs) Export added in v0.3.0

Export specifies variable names to export from referenced testcase for current step.

func (*StepTestCaseWithOptionalArgs) Name added in v0.3.0

func (*StepTestCaseWithOptionalArgs) TeardownHook added in v0.3.0

TeardownHook adds a teardown hook for current teststep.

func (*StepTestCaseWithOptionalArgs) ToStruct added in v0.3.0

func (s *StepTestCaseWithOptionalArgs) ToStruct() *TStep

func (*StepTestCaseWithOptionalArgs) Type added in v0.3.0

type StepTransaction added in v0.3.0

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

StepTransaction implements IStep interface.

func (*StepTransaction) Name added in v0.3.0

func (s *StepTransaction) Name() string

func (*StepTransaction) ToStruct added in v0.3.0

func (s *StepTransaction) ToStruct() *TStep

func (*StepTransaction) Type added in v0.3.0

func (s *StepTransaction) Type() string

type TCase

type TCase struct {
	Config    *TConfig `json:"config" yaml:"config"`
	TestSteps []*TStep `json:"teststeps" yaml:"teststeps"`
}

TCase represents testcase data structure. Each testcase includes one public config and several sequential teststeps.

func (*TCase) Dump2JSON

func (tc *TCase) Dump2JSON(path string) error

func (*TCase) Dump2YAML

func (tc *TCase) Dump2YAML(path string) error

func (*TCase) ToTestCase

func (tc *TCase) ToTestCase() (*TestCase, error)

type TConfig

type TConfig struct {
	Name              string                 `json:"name" yaml:"name"` // required
	Verify            bool                   `json:"verify,omitempty" yaml:"verify,omitempty"`
	BaseURL           string                 `json:"base_url,omitempty" yaml:"base_url,omitempty"`
	Variables         map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
	Parameters        map[string]interface{} `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	ParametersSetting *TParamsConfig         `json:"parameters_setting,omitempty" yaml:"parameters_setting,omitempty"`
	Export            []string               `json:"export,omitempty" yaml:"export,omitempty"`
	Weight            int                    `json:"weight,omitempty" yaml:"weight,omitempty"`
	Path              string                 `json:"path,omitempty" yaml:"path,omitempty"` // testcase file path
}

TConfig represents config data structure for testcase. Each testcase should contain one config part.

func NewConfig added in v0.2.2

func NewConfig(name string) *TConfig

NewConfig returns a new constructed testcase config with specified testcase name.

func (*TConfig) ExportVars added in v0.2.2

func (c *TConfig) ExportVars(vars ...string) *TConfig

ExportVars specifies variable names to export for current testcase.

func (*TConfig) SetBaseURL added in v0.2.2

func (c *TConfig) SetBaseURL(baseURL string) *TConfig

SetBaseURL sets base URL for current testcase.

func (*TConfig) SetVerifySSL added in v0.2.2

func (c *TConfig) SetVerifySSL(verify bool) *TConfig

SetVerifySSL sets whether to verify SSL for current testcase.

func (*TConfig) SetWeight added in v0.2.2

func (c *TConfig) SetWeight(weight int) *TConfig

SetWeight sets weight for current testcase, which is used in load testing.

func (*TConfig) WithParameters added in v0.2.2

func (c *TConfig) WithParameters(parameters map[string]interface{}) *TConfig

WithParameters sets parameters for current testcase.

func (*TConfig) WithVariables added in v0.2.2

func (c *TConfig) WithVariables(variables map[string]interface{}) *TConfig

WithVariables sets variables for current testcase.

type TParamsConfig added in v0.4.0

type TParamsConfig struct {
	Strategy  interface{} `json:"strategy,omitempty" yaml:"strategy,omitempty"`
	Iteration int         `json:"iteration,omitempty" yaml:"iteration,omitempty"`
	Iterators []*Iterator `json:"parameterIterator,omitempty" yaml:"parameterIterator,omitempty"` //保存参数的迭代器
}

type TStep

type TStep struct {
	Name          string                 `json:"name" yaml:"name"` // required
	Request       *Request               `json:"request,omitempty" yaml:"request,omitempty"`
	TestCase      *TestCase              `json:"testcase,omitempty" yaml:"testcase,omitempty"`
	Transaction   *Transaction           `json:"transaction,omitempty" yaml:"transaction,omitempty"`
	Rendezvous    *Rendezvous            `json:"rendezvous,omitempty" yaml:"rendezvous,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
	SetupHooks    []string               `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
	TeardownHooks []string               `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
	Extract       map[string]string      `json:"extract,omitempty" yaml:"extract,omitempty"`
	Validators    []Validator            `json:"validate,omitempty" yaml:"validate,omitempty"`
	Export        []string               `json:"export,omitempty" yaml:"export,omitempty"`
}

TStep represents teststep data structure. Each step maybe two different type: make one HTTP request or reference another testcase.

type TestCase

type TestCase struct {
	Config    *TConfig
	TestSteps []IStep
}

TestCase is a container for one testcase, which is used for testcase runner. TestCase implements ITestCase interface.

func (*TestCase) ToTCase

func (tc *TestCase) ToTCase() (*TCase, error)

func (*TestCase) ToTestCase

func (tc *TestCase) ToTestCase() (*TestCase, error)

type TestCasePath

type TestCasePath struct {
	Path string
}

TestCasePath implements ITestCase interface.

func (*TestCasePath) ToTCase

func (path *TestCasePath) ToTCase() (*TCase, error)

func (*TestCasePath) ToTestCase

func (path *TestCasePath) ToTestCase() (*TestCase, error)

type Transaction added in v0.3.0

type Transaction struct {
	Name string          `json:"name" yaml:"name"`
	Type transactionType `json:"type" yaml:"type"`
}

type Validator added in v0.2.2

type Validator struct {
	Check   string      `json:"check" yaml:"check"` // get value with jmespath
	Assert  string      `json:"assert" yaml:"assert"`
	Expect  interface{} `json:"expect" yaml:"expect"`
	Message string      `json:"msg,omitempty" yaml:"msg,omitempty"` // optional
}

Validator represents validator for one HTTP response.

Directories

Path Synopsis
cli
hrp command
examples
plugin command
internal
ga
plugin module

Jump to

Keyboard shortcuts

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