Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from httprunner/refactor-models
Browse files Browse the repository at this point in the history
v0.2.2

- refactor: update models to make API more concise
- change: remove mkdocs, move to [repo](https://github.com/httprunner/httprunner.github.io)
  • Loading branch information
debugtalk authored Dec 7, 2021
2 parents 827f934 + 5204a83 commit e7e62e7
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 265 deletions.
6 changes: 3 additions & 3 deletions boomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ func (b *Boomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
Weight: testcase.Config.Weight,
Fn: func() {
runner := NewRunner(nil).SetDebug(b.debug)
config := &testcase.Config
config := testcase.Config
for _, step := range testcase.TestSteps {
var err error
start := time.Now()
stepData, err := runner.runStep(step, config)
elapsed := time.Since(start).Nanoseconds() / int64(time.Millisecond)
if err == nil {
b.RecordSuccess(step.Type(), step.Name(), elapsed, stepData.ResponseLength)
b.RecordSuccess(step.getType(), step.name(), elapsed, stepData.responseLength)
} else {
b.RecordFailure(step.Type(), step.Name(), elapsed, err.Error())
b.RecordFailure(step.getType(), step.name(), elapsed, err.Error())
}
}
},
Expand Down
11 changes: 4 additions & 7 deletions boomer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ import (

func TestBoomerStandaloneRun(t *testing.T) {
testcase1 := &TestCase{
Config: TConfig{
Name: "TestCase1",
BaseURL: "http://httpbin.org",
},
Config: NewConfig("TestCase1").SetBaseURL("http://httpbin.org"),
TestSteps: []IStep{
Step("headers").
NewStep("headers").
GET("/headers").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("headers.\"Content-Type\"", "application/json", "check http response Content-Type"),
Step("user-agent").
NewStep("user-agent").
GET("/user-agent").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("headers.\"Content-Type\"", "application/json", "check http response Content-Type"),
Step("TestCase3").CallRefCase(&TestCase{Config: TConfig{Name: "TestCase3"}}),
NewStep("TestCase3").CallRefCase(&TestCase{Config: NewConfig("TestCase3")}),
},
}
testcase2 := &TestCasePath{demoTestCaseJSONPath}
Expand Down
2 changes: 1 addition & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (tc *TestCase) ToTCase() (*TCase, error) {
Config: tc.Config,
}
for _, step := range tc.TestSteps {
tCase.TestSteps = append(tCase.TestSteps, step.ToStruct())
tCase.TestSteps = append(tCase.TestSteps, step.toStruct())
}
return &tCase, nil
}
Expand Down
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Release History

## v0.2.2 (2021-12-06)
## v0.2.2 (2021-12-07)

- refactor: update models to make API more concise
- change: remove mkdocs, move to [repo](https://github.com/httprunner/httprunner.github.io)

## v0.2.1 (2021-12-02)
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/hrp.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Copyright 2021 debugtalk
* [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 2-Dec-2021
###### Auto generated by spf13/cobra on 7-Dec-2021
2 changes: 1 addition & 1 deletion docs/cmd/hrp_boom.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ hrp boom [flags]

* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.

###### Auto generated by spf13/cobra on 2-Dec-2021
###### Auto generated by spf13/cobra on 7-Dec-2021
2 changes: 1 addition & 1 deletion docs/cmd/hrp_har2case.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ hrp har2case harPath... [flags]

* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.

###### Auto generated by spf13/cobra on 2-Dec-2021
###### Auto generated by spf13/cobra on 7-Dec-2021
2 changes: 1 addition & 1 deletion docs/cmd/hrp_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ hrp run path... [flags]

* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.

###### Auto generated by spf13/cobra on 2-Dec-2021
###### Auto generated by spf13/cobra on 7-Dec-2021
16 changes: 7 additions & 9 deletions examples/demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ import (
)

var demoTestCase = &hrp.TestCase{
Config: hrp.TConfig{
Name: "demo with complex mechanisms",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{ // global level variables
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.Step("get with params").
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
Expand All @@ -37,7 +35,7 @@ var demoTestCase = &hrp.TestCase{
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.Step("post json data").
hrp.NewStep("post json data").
POST("/post").
WithBody(map[string]interface{}{
"foo1": "$varFoo1", // reference former extracted variable
Expand All @@ -47,7 +45,7 @@ var demoTestCase = &hrp.TestCase{
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.Step("post form data").
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{}{
Expand Down
22 changes: 9 additions & 13 deletions examples/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import (
// reference extracted variables for validation in the same step
func TestCaseExtractStepSingle(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Verify: false,
},
Config: hrp.NewConfig("run request with variables").
SetBaseURL("https://postman-echo.com").
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpRunnerPlus",
Expand Down Expand Up @@ -46,13 +44,11 @@ func TestCaseExtractStepSingle(t *testing.T) {
// reference extracted variables from previous step
func TestCaseExtractStepAssociation(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Verify: false,
},
Config: hrp.NewConfig("run request with variables").
SetBaseURL("https://postman-echo.com").
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpRunnerPlus",
Expand All @@ -71,7 +67,7 @@ func TestCaseExtractStepAssociation(t *testing.T) {
AssertEqual("$varFoo1", "bar1", "check args foo1").
AssertEqual("body.args.foo2", "bar2", "check args foo2").
AssertEqual("body.headers.\"user-agent\"", "HttpRunnerPlus", "check header user agent"),
hrp.Step("post json data").
hrp.NewStep("post json data").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
Expand Down
16 changes: 7 additions & 9 deletions examples/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import (

func TestCaseCallFunction(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with functions",
BaseURL: "https://postman-echo.com",
Verify: false,
Variables: map[string]interface{}{
Config: hrp.NewConfig("run request with functions").
SetBaseURL("https://postman-echo.com").
WithVariables(map[string]interface{}{
"n": 5,
"a": 12.3,
"b": 3.45,
},
},
}).
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
Expand All @@ -29,7 +27,7 @@ func TestCaseCallFunction(t *testing.T) {
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
hrp.Step("post json data with functions").
hrp.NewStep("post json data with functions").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
Expand Down
18 changes: 8 additions & 10 deletions examples/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (

func TestCaseBasicRequest(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "request methods testcase in hardcode",
BaseURL: "https://postman-echo.com",
Verify: false,
},
Config: hrp.NewConfig("request methods testcase in hardcode").
SetBaseURL("https://postman-echo.com").
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(map[string]string{
Expand All @@ -26,7 +24,7 @@ func TestCaseBasicRequest(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"),
hrp.Step("post raw text").
hrp.NewStep("post raw text").
POST("/post").
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
Expand All @@ -36,7 +34,7 @@ func TestCaseBasicRequest(t *testing.T) {
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"),
hrp.Step("post form data").
hrp.NewStep("post form data").
POST("/post").
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
Expand All @@ -47,7 +45,7 @@ func TestCaseBasicRequest(t *testing.T) {
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.form.foo1", "bar1", "check form foo1").
AssertEqual("body.form.foo2", "bar2", "check form foo2"),
hrp.Step("post json data").
hrp.NewStep("post json data").
POST("/post").
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
Expand All @@ -57,7 +55,7 @@ func TestCaseBasicRequest(t *testing.T) {
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.json.foo1", "bar1", "check json foo1").
AssertEqual("body.json.foo2", "bar2", "check json foo2"),
hrp.Step("put request").
hrp.NewStep("put request").
PUT("/put").
WithHeaders(map[string]string{
"User-Agent": "HttpRunnerPlus",
Expand Down
12 changes: 5 additions & 7 deletions examples/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (

func TestCaseValidateStep(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with validation",
BaseURL: "https://postman-echo.com",
Verify: false,
},
Config: hrp.NewConfig("run request with validation").
SetBaseURL("https://postman-echo.com").
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpRunnerPlus",
Expand All @@ -32,7 +30,7 @@ func TestCaseValidateStep(t *testing.T) {
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\"", "HttpRunnerPlus", "check header user agent"),
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpRunnerPlus",
Expand Down
51 changes: 20 additions & 31 deletions examples/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ import (

func TestCaseConfigVariables(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{
Config: hrp.NewConfig("run request with variables").
SetBaseURL("https://postman-echo.com").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
},
Verify: false,
},
}).SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "$var1", "foo2": "bar2"}).
WithHeaders(map[string]string{"User-Agent": "$agent"}).
Expand All @@ -41,13 +38,11 @@ func TestCaseConfigVariables(t *testing.T) {

func TestCaseStepVariables(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Verify: false,
},
Config: hrp.NewConfig("run request with variables").
SetBaseURL("https://postman-echo.com").
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1",
"agent": "HttpRunnerPlus",
Expand All @@ -74,18 +69,15 @@ func TestCaseStepVariables(t *testing.T) {

func TestCaseOverrideConfigVariables(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with variables",
BaseURL: "https://postman-echo.com",
Variables: map[string]interface{}{
Config: hrp.NewConfig("run request with variables").
SetBaseURL("https://postman-echo.com").
WithVariables(map[string]interface{}{
"var1": "bar0",
"agent": "HttpRunnerPlus",
"expectedStatusCode": 200,
},
Verify: false,
},
}).SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"var1": "bar1", // override config variable
"agent": "$agent", // reference config variable
Expand All @@ -112,20 +104,17 @@ func TestCaseOverrideConfigVariables(t *testing.T) {

func TestCaseParseVariables(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.TConfig{
Name: "run request with functions",
BaseURL: "https://postman-echo.com",
Verify: false,
Variables: map[string]interface{}{
Config: hrp.NewConfig("run request with functions").
SetBaseURL("https://postman-echo.com").
WithVariables(map[string]interface{}{
"n": 5,
"a": 12.3,
"b": 3.45,
"varFoo1": "${gen_random_string($n)}",
"varFoo2": "${max($a, $b)}", // 12.3
},
},
}).SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.Step("get with params").
hrp.NewStep("get with params").
WithVariables(map[string]interface{}{
"n": 3,
"b": 34.5,
Expand All @@ -140,7 +129,7 @@ func TestCaseParseVariables(t *testing.T) {
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
hrp.Step("post json data with functions").
hrp.NewStep("post json data with functions").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
Expand Down
Loading

0 comments on commit e7e62e7

Please sign in to comment.