fix startswith endswith and unittest

Change-Id: I3e1c6fd82812d13b4e23ecd6b23c4d57170852e1
This commit is contained in:
buyuxiang
2022-02-15 17:05:39 +08:00
parent 3f5c6f7f5d
commit e6467dfc28
16 changed files with 23 additions and 96 deletions

View File

@@ -48,7 +48,7 @@
},
{
"check": "headers.\"Content-Type\"",
"assert": "starts_with",
"assert": "startswith",
"expect": "application/json"
},
{

View File

@@ -33,7 +33,7 @@ teststeps:
expect: 200
msg: check response status code
- check: headers."Content-Type"
assert: starts_with
assert: startswith
expect: application/json
- check: body.args.foo1
assert: length_equals

View File

@@ -58,9 +58,11 @@ func TestCaseExtractStepAssociation(t *testing.T) {
WithHeaders(map[string]string{"User-Agent": "$agent"}).
Extract().
WithJmesPath("status_code", "statusCode").
WithJmesPath("headers.\"Content-Type\"", "contentType").
WithJmesPath("body.args.foo1", "varFoo1").
Validate().
AssertEqual("$statusCode", 200, "check status code").
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\"", "HttpRunnerPlus", "check header user agent"),

View File

@@ -1,81 +0,0 @@
{
"config": {
"name": "request methods testcase: validate with parameters",
"base_url": "https://httpbingo.bytedance.net"
},
"teststeps": [
{
"name": "get with params",
"request": {
"method": "GET",
"url": "/get",
"params": {
"a": 1,
"foo": "I'm a happy guy"
}
},
"validate": [
{
"check": "body.args.a",
"assert": "eq",
"expect": "1",
"msg": "check argument a"
},
{
"check": "status_code",
"assert": "lt",
"expect": 201,
"msg": "check status code"
},
{
"check": "status_code",
"assert": "gt",
"expect": 199,
"msg": "check status code"
},
{
"check": "status_code",
"assert": "ge",
"expect": 200,
"msg": "check status code"
},
{
"check": "status_code",
"assert": "le",
"expect": 200,
"msg": "check status code"
},
{
"check": "status_code",
"assert": "ne",
"expect": 199,
"msg": "check status code"
},
{
"check": "body.args.foo",
"assert": "contains",
"expect": "happy",
"msg": "check status code"
},
{
"check": "body.args.foo",
"assert": "type_match",
"expect": "string",
"msg": "check status code"
},
{
"check": "body.args.foo",
"assert": "starts_with",
"expect": "I'm",
"msg": "check status code"
},
{
"check": "body.args.foo",
"assert": "type_match",
"expect": "string",
"msg": "check status code"
}
]
}
]
}

View File

@@ -20,6 +20,7 @@ func TestCaseBasicRequest(t *testing.T) {
}).
Validate().
AssertEqual("status_code", 200, "check status code").
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.NewStep("post raw text").

View File

@@ -24,8 +24,9 @@ func TestCaseValidateStep(t *testing.T) {
Extract().
WithJmesPath("body.args.foo1", "varFoo1").
Validate().
AssertEqual("status_code", "$expectedStatusCode", "check status code"). // assert status code
AssertEqual("body.args.foo1", "bar1", "check args foo1"). // assert response json body with jmespath
AssertEqual("status_code", "$expectedStatusCode", "check status code"). // assert status code
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\"", "HttpRunnerPlus", "check header user agent"),
hrp.NewStep("get with params").

View File

@@ -22,6 +22,7 @@ func TestCaseConfigVariables(t *testing.T) {
WithHeaders(map[string]string{"User-Agent": "$agent"}).
Validate().
AssertEqual("status_code", "$expectedStatusCode", "check status code").
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\"", "HttpRunnerPlus", "check header user agent"),
@@ -51,6 +52,7 @@ func TestCaseStepVariables(t *testing.T) {
WithHeaders(map[string]string{"User-Agent": "$agent"}).
Validate().
AssertEqual("status_code", "$expectedStatusCode", "check status code").
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\"", "HttpRunnerPlus", "check header user agent"),
@@ -84,6 +86,7 @@ func TestCaseOverrideConfigVariables(t *testing.T) {
WithHeaders(map[string]string{"User-Agent": "$agent"}).
Validate().
AssertEqual("status_code", "$expectedStatusCode", "check status code").
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\"", "HttpRunnerPlus", "check header user agent"),