refactor: rename to hrp

This commit is contained in:
debugtalk
2021-10-16 23:14:16 +08:00
parent 078f7fb20f
commit 96c136e2be
46 changed files with 273 additions and 270 deletions

View File

@@ -32,7 +32,7 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
name: httpboomer # User defined upload name. Visible in Codecov UI
name: hrp(HttpRunner+) # User defined upload name. Visible in Codecov UI
token: ${{ secrets.CODECOV_TOKEN }} # Repository upload token
file: ./cover.out # Path to coverage file to upload
flags: unittests # Flag upload to group coverage metrics

View File

@@ -1,14 +1,14 @@
# HttpBoomer
# HttpRunner+ (hrp)
[![Go Reference](https://pkg.go.dev/badge/github.com/httprunner/httpboomer.svg)](https://pkg.go.dev/github.com/httprunner/httpboomer)
[![Github Actions](https://github.com/httprunner/HttpBoomer/actions/workflows/main.yml/badge.svg)](https://github.com/httprunner/HttpBoomer/actions)
[![codecov](https://codecov.io/gh/httprunner/HttpBoomer/branch/main/graph/badge.svg?token=HPCQWCD7KO)](https://codecov.io/gh/httprunner/HttpBoomer)
[![Go Report Card](https://goreportcard.com/badge/github.com/httprunner/HttpBoomer)](https://goreportcard.com/report/github.com/httprunner/HttpBoomer)
[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B27856%2Fgithub.com%2Fhttprunner%2FHttpBoomer.svg?type=shield)](https://app.fossa.com/reports/fb0e64a7-7dcf-48bb-8de9-8f0e016b903b)
[![Go Reference](https://pkg.go.dev/badge/github.com/httprunner/hrp.svg)](https://pkg.go.dev/github.com/httprunner/hrp)
[![Github Actions](https://github.com/httprunner/hrp/actions/workflows/main.yml/badge.svg)](https://github.com/httprunner/hrp/actions)
[![codecov](https://codecov.io/gh/httprunner/hrp/branch/main/graph/badge.svg?token=HPCQWCD7KO)](https://codecov.io/gh/httprunner/hrp)
[![Go Report Card](https://goreportcard.com/badge/github.com/httprunner/hrp)](https://goreportcard.com/report/github.com/httprunner/hrp)
[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B27856%2Fgithub.com%2Fhttprunner%2Fhrp.svg?type=shield)](https://app.fossa.com/reports/fb0e64a7-7dcf-48bb-8de9-8f0e016b903b)
> HttpBoomer = [HttpRunner] + [Boomer]
> hrp (HttpRunnerPlus) = [HttpRunner] + [Boomer]
HttpBoomer is a golang implementation of [HttpRunner]. Ideally, HttpBoomer will be fully compatible with HttpRunner, including testcase format and usage. What's more, HttpBoomer will integrate Boomer natively to be a better load generator for [locust].
`hrp` is a golang implementation of [HttpRunner]. Ideally, `hrp` will be fully compatible with HttpRunner, including testcase format and usage. What's more, `hrp` will integrate Boomer natively to be a better load generator for [locust].
## Key Features
@@ -27,23 +27,23 @@ HttpBoomer is a golang implementation of [HttpRunner]. Ideally, HttpBoomer will
### Install
```bash
$ go get -u github.com/httprunner/httpboomer
$ go get -u github.com/httprunner/hrp
```
### Examples
This is an example of HttpBoomer testcase. You can find more in the [`examples`][examples] directory.
This is an example of `hrp` testcase. You can find more in the [`examples`][examples] directory.
```go
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
func TestCaseDemo(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "demo with complex mechanisms",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{ // global level variables
@@ -54,8 +54,8 @@ func TestCaseDemo(t *testing.T) {
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
},
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("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
@@ -63,7 +63,7 @@ func TestCaseDemo(t *testing.T) {
}).
GET("/get").
WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). // request with headers
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). // request with headers
Extract().
WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath
Validate().
@@ -72,7 +72,7 @@ func TestCaseDemo(t *testing.T) {
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
httpboomer.Step("post json data").
hrp.Step("post json data").
POST("/post").
WithJSON(map[string]interface{}{
"foo1": "$varFoo1", // reference former extracted variable
@@ -85,7 +85,7 @@ func TestCaseDemo(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"time"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"testing"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"os"
@@ -28,7 +28,7 @@ var demoTestCase = &TestCase{
}).
GET("/get").
WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). // request with headers
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). // request with headers
Extract().
WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath
Validate().

25
docs/cmd/hrp.md Normal file
View File

@@ -0,0 +1,25 @@
## hrp
One-stop solution for HTTP(S) testing.
### Synopsis
hrp(HttpRunnerPlus) is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨
License: Apache-2.0
Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk
### Options
```
-h, --help help for hrp
```
### SEE ALSO
* [hrp boom](hrp_boom.md) - run load test with boomer
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
* [hrp run](hrp_run.md) - run API test
###### Auto generated by spf13/cobra on 16-Oct-2021

View File

@@ -1,4 +1,4 @@
## httpboomer boom
## hrp boom
run load test with boomer
@@ -7,15 +7,15 @@ run load test with boomer
run yaml/json testcase files for load test
```
httpboomer boom [flags]
hrp boom [flags]
```
### Examples
```
$ httpboomer boom demo.json # run specified json testcase file
$ httpboomer boom demo.yaml # run specified yaml testcase file
$ httpboomer boom examples/ # run testcases in specified folder
$ hrp boom demo.json # run specified json testcase file
$ hrp boom demo.yaml # run specified yaml testcase file
$ hrp boom examples/ # run testcases in specified folder
```
### Options
@@ -35,6 +35,6 @@ httpboomer boom [flags]
### SEE ALSO
* [httpboomer](httpboomer.md) - One-stop solution for HTTP(S) testing.
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 11-Oct-2021
###### Auto generated by spf13/cobra on 16-Oct-2021

23
docs/cmd/hrp_har2case.md Normal file
View File

@@ -0,0 +1,23 @@
## hrp har2case
Convert HAR to json/yaml testcase files
### Synopsis
Convert HAR to json/yaml testcase files
```
hrp har2case path... [flags]
```
### Options
```
-h, --help help for har2case
```
### SEE ALSO
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 16-Oct-2021

33
docs/cmd/hrp_run.md Normal file
View File

@@ -0,0 +1,33 @@
## hrp run
run API test
### Synopsis
run yaml/json testcase files for API test
```
hrp run path... [flags]
```
### Examples
```
$ hrp run demo.json # run specified json testcase file
$ hrp run demo.yaml # run specified yaml testcase file
$ hrp run examples/ # run testcases in specified folder
```
### Options
```
-h, --help help for run
-p, --proxy-url string set proxy url
-s, --silent disable logging request & response details
```
### SEE ALSO
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 16-Oct-2021

View File

@@ -1,25 +0,0 @@
## httpboomer
One-stop solution for HTTP(S) testing.
### Synopsis
HttpBoomer is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨
License: Apache-2.0
Github: https://github.com/httprunner/httpboomer
Copyright 2021 debugtalk
### Options
```
-h, --help help for httpboomer
```
### SEE ALSO
* [httpboomer boom](httpboomer_boom.md) - run load test with boomer
* [httpboomer har2case](httpboomer_har2case.md) - Convert HAR to json/yaml testcase files
* [httpboomer run](httpboomer_run.md) - run API test
###### Auto generated by spf13/cobra on 11-Oct-2021

View File

@@ -1,23 +0,0 @@
## httpboomer har2case
Convert HAR to json/yaml testcase files
### Synopsis
Convert HAR to json/yaml testcase files
```
httpboomer har2case path... [flags]
```
### Options
```
-h, --help help for har2case
```
### SEE ALSO
* [httpboomer](httpboomer.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 11-Oct-2021

View File

@@ -1,32 +0,0 @@
## httpboomer run
run API test
### Synopsis
run yaml/json testcase files for API test
```
httpboomer run path... [flags]
```
### Examples
```
$ httpboomer run demo.json # run specified json testcase file
$ httpboomer run demo.yaml # run specified yaml testcase file
$ httpboomer run examples/ # run testcases in specified folder
```
### Options
```
-h, --help help for run
-s, --silent Disable logging request & response details
```
### SEE ALSO
* [httpboomer](httpboomer.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 11-Oct-2021

View File

@@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra/doc"
"github.com/httprunner/httpboomer/httpboomer/cmd"
"github.com/httprunner/hrp/hrp/cmd"
)
// run this test to generate markdown docs

View File

@@ -21,7 +21,7 @@
},
{
"name": "User-Agent",
"value": "HttpBoomer"
"value": "HttpRunnerPlus"
},
{
"name": "Accept-Encoding",

View File

@@ -21,7 +21,7 @@
"foo2": "$varFoo2"
},
"headers": {
"User-Agent": "HttpBoomer"
"User-Agent": "HttpRunnerPlus"
}
},
"variables": {

View File

@@ -16,7 +16,7 @@ teststeps:
foo1: $varFoo1
foo2: $varFoo2
headers:
User-Agent: HttpBoomer
User-Agent: HttpRunnerPlus
variables:
b: 34.5
"n": 3

View File

@@ -3,12 +3,12 @@ package examples
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
func TestCaseDemo(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "demo with complex mechanisms",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{ // global level variables
@@ -19,8 +19,8 @@ func TestCaseDemo(t *testing.T) {
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
},
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("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
@@ -28,7 +28,7 @@ func TestCaseDemo(t *testing.T) {
}).
GET("/get").
WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}). // request with headers
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). // request with headers
Extract().
WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath
Validate().
@@ -37,7 +37,7 @@ func TestCaseDemo(t *testing.T) {
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
httpboomer.Step("post json data").
hrp.Step("post json data").
POST("/post").
WithBody(map[string]interface{}{
"foo1": "$varFoo1", // reference former extracted variable
@@ -47,7 +47,7 @@ func TestCaseDemo(t *testing.T) {
AssertEqual("status_code", 200, "check status code").
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
AssertEqual("body.json.foo2", 12.3, "check args foo2"),
httpboomer.Step("post form data").
hrp.Step("post form data").
POST("/post").
WithParams(map[string]interface{}{
"foo1": "$varFoo1", // reference former extracted variable
@@ -60,7 +60,7 @@ func TestCaseDemo(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -3,22 +3,22 @@ package examples
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
// reference extracted variables for validation in the same step
func TestCaseExtractStepSingle(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
}).
GET("/get").
@@ -33,11 +33,11 @@ func TestCaseExtractStepSingle(t *testing.T) {
AssertEqual("$contentType", "application/json; charset=utf-8", "check header Content-Type"). // assert with extracted variable from current step
AssertEqual("$varFoo1", "bar1", "check args foo1"). // assert with extracted variable from current step
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}
@@ -45,17 +45,17 @@ func TestCaseExtractStepSingle(t *testing.T) {
// reference extracted variables from previous step
func TestCaseExtractStepAssociation(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
}).
GET("/get").
WithParams(map[string]interface{}{"foo1": "$var1", "foo2": "bar2"}).
@@ -70,10 +70,10 @@ func TestCaseExtractStepAssociation(t *testing.T) {
AssertEqual("$contentType", "application/json; charset=utf-8", "check header Content-Type").
AssertEqual("$varFoo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
httpboomer.Step("post json data").
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
hrp.Step("post json data").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate().
AssertEqual("status_code", "$statusCode", "check status code"). // assert with extracted variable from previous step
@@ -82,7 +82,7 @@ func TestCaseExtractStepAssociation(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -3,12 +3,12 @@ package examples
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
func TestCaseCallFunction(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with functions",
BaseURL: "https://postman-echo.com",
Verify: false,
@@ -18,20 +18,20 @@ func TestCaseCallFunction(t *testing.T) {
"b": 3.45,
},
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
Extract().
WithJmesPath("body.args.foo1", "varFoo1").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertLengthEqual("body.args.foo1", 5, "check args foo1").
AssertEqual("body.args.foo2", "12.3", "check args foo2"), // notice: request params value will be converted to string
httpboomer.Step("post json data with functions").
hrp.Step("post json data with functions").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
Validate().
AssertEqual("status_code", 200, "check status code").
@@ -40,7 +40,7 @@ func TestCaseCallFunction(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -3,53 +3,53 @@ package examples
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
func TestCaseBasicRequest(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "request methods testcase in hardcode",
BaseURL: "https://postman-echo.com",
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("headers.Connection", "keep-alive", "check header Connection").
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
AssertEqual("body.args.foo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2"),
httpboomer.Step("post raw text").
hrp.Step("post raw text").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "text/plain"}).
WithBody("This is expected to be sent back as part of response body.").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.data", "This is expected to be sent back as part of response body.", "check data"),
httpboomer.Step("post form data").
hrp.Step("post form data").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "application/x-www-form-urlencoded"}).
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.form.foo1", "bar1", "check form foo1").
AssertEqual("body.form.foo2", "bar2", "check form foo2"),
httpboomer.Step("post json data").
hrp.Step("post json data").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.json.foo1", "bar1", "check json foo1").
AssertEqual("body.json.foo2", "bar2", "check json foo2"),
httpboomer.Step("put request").
hrp.Step("put request").
PUT("/put").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "text/plain"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "text/plain"}).
WithBody("This is expected to be sent back as part of response body.").
Validate().
AssertEqual("status_code", 200, "check status code").
@@ -57,7 +57,7 @@ func TestCaseBasicRequest(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -3,21 +3,21 @@ package examples
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
func TestCaseValidateStep(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with validation",
BaseURL: "https://postman-echo.com",
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
}).
GET("/get").
@@ -31,11 +31,11 @@ func TestCaseValidateStep(t *testing.T) {
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type"). // assert response header, with double quotes
AssertEqual("body.args.foo1", "bar1", "check args foo1"). // assert response json body with jmespath
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
httpboomer.Step("get with params").
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
}).
GET("/get").
WithParams(map[string]interface{}{"foo1": "$var1", "foo2": "bar2"}).
@@ -51,7 +51,7 @@ func TestCaseValidateStep(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -3,23 +3,23 @@ package examples
import (
"testing"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
func TestCaseConfigVariables(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{
"var1": "bar1",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
},
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "$var1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "$agent"}).
@@ -29,28 +29,28 @@ func TestCaseConfigVariables(t *testing.T) {
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
AssertEqual("body.args.foo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}
}
func TestCaseStepVariables(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
}).
GET("/get").
@@ -62,30 +62,30 @@ func TestCaseStepVariables(t *testing.T) {
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
AssertEqual("body.args.foo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}
}
func TestCaseOverrideConfigVariables(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{
"var1": "bar0",
"agent": "HttpBoomer",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
},
Verify: false,
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1", // override config variable
"agent": "$agent", // reference config variable
@@ -100,19 +100,19 @@ func TestCaseOverrideConfigVariables(t *testing.T) {
AssertEqual("headers.\"Content-Type\"", "application/json; charset=utf-8", "check header Content-Type").
AssertEqual("body.args.foo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpBoomer", "check header user agent"),
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}
}
func TestCaseParseVariables(t *testing.T) {
testcase := &httpboomer.TestCase{
Config: httpboomer.TConfig{
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with functions",
BaseURL: "https://postman-echo.com",
Verify: false,
@@ -124,8 +124,8 @@ func TestCaseParseVariables(t *testing.T) {
"varFoo2": "${max($a, $b)}", // 12.3
},
},
TestSteps: []httpboomer.IStep{
httpboomer.Step("get with params").
TestSteps: []hrp.IStep{
hrp.Step("get with params").
WithVariables(map[string]interface{}{
"n": 3,
"b": 34.5,
@@ -133,16 +133,16 @@ func TestCaseParseVariables(t *testing.T) {
}).
GET("/get").
WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
Extract().
WithJmesPath("body.args.foo1", "varFoo1").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertLengthEqual("body.args.foo1", 5, "check args foo1").
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
httpboomer.Step("post json data with functions").
hrp.Step("post json data with functions").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
Validate().
AssertEqual("status_code", 200, "check status code").
@@ -151,7 +151,7 @@ func TestCaseParseVariables(t *testing.T) {
},
}
err := httpboomer.Run(t, testcase)
err := hrp.Run(t, testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import "fmt"

4
go.mod
View File

@@ -1,4 +1,4 @@
module github.com/httprunner/httpboomer
module github.com/httprunner/hrp
go 1.16
@@ -11,7 +11,7 @@ require (
github.com/maja42/goval v1.2.1
github.com/myzhan/boomer v1.6.0
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil v3.21.8+incompatible // indirect
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0

View File

@@ -1,6 +1,6 @@
# har2case
Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner and HttpBoomer.
Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner and HttpRunner+.
## Install

View File

@@ -11,8 +11,9 @@ import (
"path/filepath"
"strings"
"github.com/httprunner/httpboomer"
"github.com/pkg/errors"
"github.com/httprunner/hrp"
)
func NewHAR(path string) *HAR {
@@ -49,13 +50,13 @@ func (h *HAR) GenYAML() (yamlPath string, err error) {
return
}
func (h *HAR) makeTestCase() (*httpboomer.TCase, error) {
func (h *HAR) makeTestCase() (*hrp.TCase, error) {
teststeps, err := h.prepareTestSteps()
if err != nil {
return nil, err
}
tCase := &httpboomer.TCase{
tCase := &hrp.TCase{
Config: *h.prepareConfig(),
TestSteps: teststeps,
}
@@ -83,21 +84,21 @@ func (h *HAR) load() (*Har, error) {
return har, nil
}
func (h *HAR) prepareConfig() *httpboomer.TConfig {
return &httpboomer.TConfig{
func (h *HAR) prepareConfig() *hrp.TConfig {
return &hrp.TConfig{
Name: "testcase description",
Variables: make(map[string]interface{}),
Verify: false,
}
}
func (h *HAR) prepareTestSteps() ([]*httpboomer.TStep, error) {
func (h *HAR) prepareTestSteps() ([]*hrp.TStep, error) {
har, err := h.load()
if err != nil {
return nil, err
}
var steps []*httpboomer.TStep
var steps []*hrp.TStep
for _, entry := range har.Log.Entries {
step, err := h.prepareTestStep(&entry)
if err != nil {
@@ -109,12 +110,12 @@ func (h *HAR) prepareTestSteps() ([]*httpboomer.TStep, error) {
return steps, nil
}
func (h *HAR) prepareTestStep(entry *Entry) (*httpboomer.TStep, error) {
func (h *HAR) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
log.Printf("[prepareTestStep] %v %v", entry.Request.Method, entry.Request.URL)
tStep := &TStep{
TStep: httpboomer.TStep{
Request: &httpboomer.TRequest{},
Validators: make([]httpboomer.TValidator, 0),
TStep: hrp.TStep{
Request: &hrp.TRequest{},
Validators: make([]hrp.TValidator, 0),
},
}
if err := tStep.makeRequestMethod(entry); err != nil {
@@ -142,11 +143,11 @@ func (h *HAR) prepareTestStep(entry *Entry) (*httpboomer.TStep, error) {
}
type TStep struct {
httpboomer.TStep
hrp.TStep
}
func (s *TStep) makeRequestMethod(entry *Entry) error {
s.Request.Method = httpboomer.EnumHTTPMethod(entry.Request.Method)
s.Request.Method = hrp.EnumHTTPMethod(entry.Request.Method)
return nil
}
@@ -224,7 +225,7 @@ func (s *TStep) makeRequestBody(entry *Entry) error {
func (s *TStep) makeValidate(entry *Entry) error {
// make validator for response status code
s.Validators = append(s.Validators, httpboomer.TValidator{
s.Validators = append(s.Validators, hrp.TValidator{
Check: "status_code",
Assert: "equals",
Expect: entry.Response.Status,
@@ -235,7 +236,7 @@ func (s *TStep) makeValidate(entry *Entry) error {
for _, header := range entry.Response.Headers {
// assert Content-Type
if strings.EqualFold(header.Name, "Content-Type") {
s.Validators = append(s.Validators, httpboomer.TValidator{
s.Validators = append(s.Validators, hrp.TValidator{
Check: "headers.Content-Type",
Assert: "equals",
Expect: header.Value,
@@ -276,7 +277,7 @@ func (s *TStep) makeValidate(entry *Entry) error {
case []interface{}:
continue
default:
s.Validators = append(s.Validators, httpboomer.TValidator{
s.Validators = append(s.Validators, hrp.TValidator{
Check: fmt.Sprintf("body.%s", key),
Assert: "equals",
Expect: v,

View File

@@ -79,7 +79,7 @@ func TestMakeTestCase(t *testing.T) {
}
// make request headers
if !assert.Equal(t, "HttpBoomer", tCase.TestSteps[0].Request.Headers["User-Agent"]) {
if !assert.Equal(t, "HttpRunnerPlus", tCase.TestSteps[0].Request.Headers["User-Agent"]) {
t.Fail()
}
if !assert.Equal(t, "postman-echo.com", tCase.TestSteps[0].Request.Headers["Host"]) {

1
hrp/README.md Normal file
View File

@@ -0,0 +1 @@
# HttpRunner+ cli

View File

@@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
// boomCmd represents the boom command
@@ -13,16 +13,16 @@ var boomCmd = &cobra.Command{
Use: "boom",
Short: "run load test with boomer",
Long: `run yaml/json testcase files for load test`,
Example: ` $ httpboomer boom demo.json # run specified json testcase file
$ httpboomer boom demo.yaml # run specified yaml testcase file
$ httpboomer boom examples/ # run testcases in specified folder`,
Example: ` $ hrp boom demo.json # run specified json testcase file
$ hrp boom demo.yaml # run specified yaml testcase file
$ hrp boom examples/ # run testcases in specified folder`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var paths []httpboomer.ITestCase
var paths []hrp.ITestCase
for _, arg := range args {
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
paths = append(paths, &hrp.TestCasePath{Path: arg})
}
boomer := httpboomer.NewBoomer(masterHost, masterPort)
boomer := hrp.NewBoomer(masterHost, masterPort)
boomer.EnableCPUProfile(cpuProfile, cpuProfileDuration)
boomer.EnableMemoryProfile(memoryProfile, memoryProfileDuration)
boomer.Run(paths...)

View File

@@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/httprunner/httpboomer/har2case"
"github.com/httprunner/hrp/har2case"
)
// har2caseCmd represents the har2case command

View File

@@ -6,19 +6,19 @@ import (
"github.com/spf13/cobra"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "httpboomer",
Use: "hrp",
Short: "One-stop solution for HTTP(S) testing.",
Long: `HttpBoomer is the next generation for HttpRunner. Enjoy! 🚀
Long: `hrp(HttpRunnerPlus) is the next generation for HttpRunner. Enjoy! 🚀
License: Apache-2.0
Github: https://github.com/httprunner/httpboomer
Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk`,
Version: httpboomer.VERSION,
Version: hrp.VERSION,
}
// Execute adds all child commands to the root command and sets flags appropriately.

View File

@@ -3,7 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"
"github.com/httprunner/httpboomer"
"github.com/httprunner/hrp"
)
// runCmd represents the run command
@@ -11,16 +11,16 @@ var runCmd = &cobra.Command{
Use: "run path...",
Short: "run API test",
Long: `run yaml/json testcase files for API test`,
Example: ` $ httpboomer run demo.json # run specified json testcase file
$ httpboomer run demo.yaml # run specified yaml testcase file
$ httpboomer run examples/ # run testcases in specified folder`,
Example: ` $ hrp run demo.json # run specified json testcase file
$ hrp run demo.yaml # run specified yaml testcase file
$ hrp run examples/ # run testcases in specified folder`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var paths []httpboomer.ITestCase
var paths []hrp.ITestCase
for _, arg := range args {
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
paths = append(paths, &hrp.TestCasePath{Path: arg})
}
runner := httpboomer.NewRunner().SetDebug(!silentFlag)
runner := hrp.NewRunner().SetDebug(!silentFlag)
if proxyUrl != "" {
runner.SetProxyUrl(proxyUrl)
}

7
hrp/main.go Normal file
View File

@@ -0,0 +1,7 @@
package main
import "github.com/httprunner/hrp/hrp/cmd"
func main() {
cmd.Execute()
}

View File

@@ -1 +0,0 @@
# httpboomer cli

View File

@@ -1,7 +0,0 @@
package main
import "github.com/httprunner/httpboomer/httpboomer/cmd"
func main() {
cmd.Execute()
}

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
type EnumHTTPMethod string
@@ -43,6 +43,7 @@ type TValidator struct {
type TStep struct {
Name string `json:"name" yaml:"name"`
Transaction string `json:"transaction,omitempty" yaml:"transaction,omitempty"`
Request *TRequest `json:"request,omitempty" yaml:"request,omitempty"`
TestCase *TestCase `json:"testcase,omitempty" yaml:"testcase,omitempty"`
Variables map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"encoding/json"
@@ -9,7 +9,7 @@ import (
"regexp"
"strings"
"github.com/httprunner/httpboomer/builtin"
"github.com/httprunner/hrp/builtin"
"github.com/maja42/goval"
)

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"sort"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"encoding/json"
@@ -9,7 +9,7 @@ import (
"github.com/imroc/req"
"github.com/jmespath/go-jmespath"
"github.com/httprunner/httpboomer/builtin"
"github.com/httprunner/hrp/builtin"
)
func NewResponseObject(t *testing.T, resp *req.Resp) (*ResponseObject, error) {

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"log"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"testing"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import "fmt"

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"testing"
@@ -8,7 +8,7 @@ var (
stepGET = Step("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithCookies(map[string]string{"user": "debugtalk"}).
Validate().
AssertEqual("status_code", 200, "check status code").
@@ -19,7 +19,7 @@ var (
stepPOSTData = Step("post form data").
POST("/post").
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus", "Content-Type": "application/x-www-form-urlencoded"}).
WithBody("a=1&b=2").
WithCookies(map[string]string{"user": "debugtalk"}).
Validate().
@@ -37,7 +37,7 @@ func TestRunRequestGetToStruct(t *testing.T) {
if tStep.Request.Params["foo1"] != "bar1" || tStep.Request.Params["foo2"] != "bar2" {
t.Fatalf("tStep.Request.Params mismatch")
}
if tStep.Request.Headers["User-Agent"] != "HttpBoomer" {
if tStep.Request.Headers["User-Agent"] != "HttpRunnerPlus" {
t.Fatalf("tStep.Request.Headers mismatch")
}
if tStep.Request.Cookies["user"] != "debugtalk" {
@@ -59,7 +59,7 @@ func TestRunRequestPostDataToStruct(t *testing.T) {
if tStep.Request.Params["foo1"] != "bar1" || tStep.Request.Params["foo2"] != "bar2" {
t.Fatalf("tStep.Request.Params mismatch")
}
if tStep.Request.Headers["User-Agent"] != "HttpBoomer" {
if tStep.Request.Headers["User-Agent"] != "HttpRunnerPlus" {
t.Fatalf("tStep.Request.Headers mismatch")
}
if tStep.Request.Cookies["user"] != "debugtalk" {

View File

@@ -1,4 +1,4 @@
package httpboomer
package hrp
import (
"fmt"

View File

@@ -1,3 +1,3 @@
package httpboomer
package hrp
const VERSION = "v0.1.0"