mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 08:19:45 +08:00
refactor: TestCase, TSteps -> Steps
This commit is contained in:
@@ -109,7 +109,7 @@ func LoadCurlCase(path string) (*hrp.TestCase, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tCase.TSteps = append(tCase.TSteps, tSteps...)
|
||||
tCase.Steps = append(tCase.Steps, tSteps...)
|
||||
}
|
||||
err = tCase.MakeCompat()
|
||||
if err != nil {
|
||||
|
||||
@@ -13,29 +13,29 @@ func TestLoadCurlCase(t *testing.T) {
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !assert.Equal(t, 6, len(tCase.TSteps)) {
|
||||
if !assert.Equal(t, 6, len(tCase.Steps)) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// curl httpbin.org
|
||||
if !assert.Equal(t, "curl httpbin.org", tCase.TSteps[0].Name) {
|
||||
if !assert.Equal(t, "curl httpbin.org", tCase.Steps[0].Name) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.EqualValues(t, "GET", tCase.TSteps[0].Request.Method) {
|
||||
if !assert.EqualValues(t, "GET", tCase.Steps[0].Request.Method) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "http://httpbin.org", tCase.TSteps[0].Request.URL) {
|
||||
if !assert.Equal(t, "http://httpbin.org", tCase.Steps[0].Request.URL) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// curl https://httpbin.org/get?key1=value1&key2=value2
|
||||
if !assert.Equal(t, "https://httpbin.org/get", tCase.TSteps[1].Request.URL) {
|
||||
if !assert.Equal(t, "https://httpbin.org/get", tCase.Steps[1].Request.URL) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]interface{}{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
}, tCase.TSteps[1].Request.Params) {
|
||||
}, tCase.Steps[1].Request.Params) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
@@ -43,13 +43,13 @@ func TestLoadCurlCase(t *testing.T) {
|
||||
// -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" \
|
||||
// -d '{"type":"A","name":"www","data":"162.10.66.0","priority":null,"port":null,"weight":null}' \
|
||||
// "https://httpbin.org/post"
|
||||
if !assert.EqualValues(t, "POST", tCase.TSteps[2].Request.Method) {
|
||||
if !assert.EqualValues(t, "POST", tCase.Steps[2].Request.Method) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"Authorization": "Bearer b7d03a6947b217efb6f3ec3bd3504582",
|
||||
"Content-Type": "application/json",
|
||||
}, tCase.TSteps[2].Request.Headers) {
|
||||
}, tCase.Steps[2].Request.Headers) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]interface{}{
|
||||
@@ -59,7 +59,7 @@ func TestLoadCurlCase(t *testing.T) {
|
||||
"priority": nil,
|
||||
"type": "A",
|
||||
"weight": nil,
|
||||
}, tCase.TSteps[2].Request.Body) {
|
||||
}, tCase.Steps[2].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestLoadCurlCase(t *testing.T) {
|
||||
"dummyName": "dummyFile",
|
||||
"file1": "@file1.txt",
|
||||
"file2": "@file2.txt",
|
||||
}, tCase.TSteps[3].Request.Upload) {
|
||||
}, tCase.Steps[3].Request.Upload) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestLoadCurlCase(t *testing.T) {
|
||||
"shipment[is_return]": "true",
|
||||
"shipment[parcel][id]": "prcl_WDv2VzHp",
|
||||
"shipment[to_address][id]": "adr_HrBKVA85",
|
||||
}, tCase.TSteps[4].Request.Body) {
|
||||
}, tCase.Steps[4].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
@@ -92,13 +92,13 @@ func TestLoadCurlCase(t *testing.T) {
|
||||
// --data "key1=value+1&key2=value%3A2"
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}, tCase.TSteps[5].Request.Headers) {
|
||||
}, tCase.Steps[5].Request.Headers) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]interface{}{
|
||||
"key1": "value 1",
|
||||
"key2": "value:2",
|
||||
}, tCase.TSteps[5].Request.Body) {
|
||||
}, tCase.Steps[5].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ func (c *CaseHar) ToTestCase() (*hrp.TestCase, error) {
|
||||
|
||||
tCase := &hrp.TestCase{
|
||||
Config: c.prepareConfig(),
|
||||
TSteps: teststeps,
|
||||
Steps: teststeps,
|
||||
}
|
||||
err = tCase.MakeCompat()
|
||||
if err != nil {
|
||||
|
||||
@@ -36,60 +36,60 @@ func TestLoadTCaseFromHAR(t *testing.T) {
|
||||
}
|
||||
|
||||
// make request method
|
||||
if !assert.EqualValues(t, "GET", tCase.TSteps[0].Request.Method) {
|
||||
if !assert.EqualValues(t, "GET", tCase.Steps[0].Request.Method) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.EqualValues(t, "POST", tCase.TSteps[1].Request.Method) {
|
||||
if !assert.EqualValues(t, "POST", tCase.Steps[1].Request.Method) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// make request url
|
||||
if !assert.Equal(t, "https://postman-echo.com/get", tCase.TSteps[0].Request.URL) {
|
||||
if !assert.Equal(t, "https://postman-echo.com/get", tCase.Steps[0].Request.URL) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "https://postman-echo.com/post", tCase.TSteps[1].Request.URL) {
|
||||
if !assert.Equal(t, "https://postman-echo.com/post", tCase.Steps[1].Request.URL) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// make request params
|
||||
if !assert.Equal(t, "HDnY8", tCase.TSteps[0].Request.Params["foo1"]) {
|
||||
if !assert.Equal(t, "HDnY8", tCase.Steps[0].Request.Params["foo1"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// make request cookies
|
||||
if !assert.NotEmpty(t, tCase.TSteps[1].Request.Cookies["sails.sid"]) {
|
||||
if !assert.NotEmpty(t, tCase.Steps[1].Request.Cookies["sails.sid"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// make request headers
|
||||
if !assert.Equal(t, "HttpRunnerPlus", tCase.TSteps[0].Request.Headers["User-Agent"]) {
|
||||
if !assert.Equal(t, "HttpRunnerPlus", tCase.Steps[0].Request.Headers["User-Agent"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "postman-echo.com", tCase.TSteps[0].Request.Headers["Host"]) {
|
||||
if !assert.Equal(t, "postman-echo.com", tCase.Steps[0].Request.Headers["Host"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// make request data
|
||||
if !assert.Equal(t, nil, tCase.TSteps[0].Request.Body) {
|
||||
if !assert.Equal(t, nil, tCase.Steps[0].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]interface{}{"foo1": "HDnY8", "foo2": 12.3}, tCase.TSteps[1].Request.Body) {
|
||||
if !assert.Equal(t, map[string]interface{}{"foo1": "HDnY8", "foo2": 12.3}, tCase.Steps[1].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]string{"foo1": "HDnY8", "foo2": "12.3"}, tCase.TSteps[2].Request.Body) {
|
||||
if !assert.Equal(t, map[string]string{"foo1": "HDnY8", "foo2": "12.3"}, tCase.Steps[2].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// make validators
|
||||
validator, ok := tCase.TSteps[0].Validators[0].(hrp.Validator)
|
||||
validator, ok := tCase.Steps[0].Validators[0].(hrp.Validator)
|
||||
if !ok || !assert.Equal(t, "status_code", validator.Check) {
|
||||
t.Fatal()
|
||||
}
|
||||
validator, ok = tCase.TSteps[0].Validators[1].(hrp.Validator)
|
||||
validator, ok = tCase.Steps[0].Validators[1].(hrp.Validator)
|
||||
if !ok || !assert.Equal(t, "headers.\"Content-Type\"", validator.Check) {
|
||||
t.Fatal()
|
||||
}
|
||||
validator, ok = tCase.TSteps[0].Validators[2].(hrp.Validator)
|
||||
validator, ok = tCase.Steps[0].Validators[2].(hrp.Validator)
|
||||
if !ok || !assert.Equal(t, "body.url", validator.Check) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func LoadJSONCase(path string) (*hrp.TestCase, error) {
|
||||
return nil, errors.Wrap(err, "load json file failed")
|
||||
}
|
||||
|
||||
if caseJSON.TSteps == nil {
|
||||
if caseJSON.Steps == nil {
|
||||
return nil, errors.New("invalid json case file, missing teststeps")
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ func (c *CasePostman) ToTestCase() (*hrp.TestCase, error) {
|
||||
}
|
||||
tCase := &hrp.TestCase{
|
||||
Config: c.prepareConfig(),
|
||||
TSteps: teststeps,
|
||||
Steps: teststeps,
|
||||
}
|
||||
err = tCase.MakeCompat()
|
||||
if err != nil {
|
||||
|
||||
@@ -28,51 +28,51 @@ func TestMakeTestCaseFromCollection(t *testing.T) {
|
||||
t.Fatal()
|
||||
}
|
||||
// check method
|
||||
if !assert.EqualValues(t, "GET", tCase.TSteps[0].Request.Method) {
|
||||
if !assert.EqualValues(t, "GET", tCase.Steps[0].Request.Method) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.EqualValues(t, "POST", tCase.TSteps[1].Request.Method) {
|
||||
if !assert.EqualValues(t, "POST", tCase.Steps[1].Request.Method) {
|
||||
t.Fatal()
|
||||
}
|
||||
// check url
|
||||
if !assert.Equal(t, "https://postman-echo.com/get", tCase.TSteps[0].Request.URL) {
|
||||
if !assert.Equal(t, "https://postman-echo.com/get", tCase.Steps[0].Request.URL) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "https://postman-echo.com/post", tCase.TSteps[1].Request.URL) {
|
||||
if !assert.Equal(t, "https://postman-echo.com/post", tCase.Steps[1].Request.URL) {
|
||||
t.Fatal()
|
||||
}
|
||||
// check params
|
||||
if !assert.Equal(t, "v1", tCase.TSteps[0].Request.Params["k1"]) {
|
||||
if !assert.Equal(t, "v1", tCase.Steps[0].Request.Params["k1"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
// check cookies (pass, postman collection doesn't contain cookies)
|
||||
// check headers
|
||||
if !assert.Equal(t, "application/x-www-form-urlencoded", tCase.TSteps[2].Request.Headers["Content-Type"]) {
|
||||
if !assert.Equal(t, "application/x-www-form-urlencoded", tCase.Steps[2].Request.Headers["Content-Type"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "application/json", tCase.TSteps[3].Request.Headers["Content-Type"]) {
|
||||
if !assert.Equal(t, "application/json", tCase.Steps[3].Request.Headers["Content-Type"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "text/plain", tCase.TSteps[4].Request.Headers["Content-Type"]) {
|
||||
if !assert.Equal(t, "text/plain", tCase.Steps[4].Request.Headers["Content-Type"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "HttpRunner", tCase.TSteps[5].Request.Headers["User-Agent"]) {
|
||||
if !assert.Equal(t, "HttpRunner", tCase.Steps[5].Request.Headers["User-Agent"]) {
|
||||
t.Fatal()
|
||||
}
|
||||
// check body
|
||||
if !assert.Equal(t, nil, tCase.TSteps[0].Request.Body) {
|
||||
if !assert.Equal(t, nil, tCase.Steps[0].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]string{"k1": "v1", "k2": "v2"}, tCase.TSteps[2].Request.Body) {
|
||||
if !assert.Equal(t, map[string]string{"k1": "v1", "k2": "v2"}, tCase.Steps[2].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]interface{}{"k1": "v1", "k2": "v2"}, tCase.TSteps[3].Request.Body) {
|
||||
if !assert.Equal(t, map[string]interface{}{"k1": "v1", "k2": "v2"}, tCase.Steps[3].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, "have a nice day", tCase.TSteps[4].Request.Body) {
|
||||
if !assert.Equal(t, "have a nice day", tCase.Steps[4].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, nil, tCase.TSteps[5].Request.Body) {
|
||||
if !assert.Equal(t, nil, tCase.Steps[5].Request.Body) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func (c *TCaseConverter) overrideWithProfile(path string) error {
|
||||
}
|
||||
|
||||
log.Info().Interface("profile", profile).Msg("override with profile")
|
||||
for _, step := range c.tCase.TSteps {
|
||||
for _, step := range c.tCase.Steps {
|
||||
// override original headers and cookies
|
||||
if profile.Override {
|
||||
step.Request.Headers = make(map[string]string)
|
||||
|
||||
@@ -47,12 +47,12 @@ func TestLoadHARWithProfileOverride(t *testing.T) {
|
||||
for i := 0; i < 3; i++ {
|
||||
if !assert.Equal(t,
|
||||
map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
|
||||
converter.tCase.TSteps[i].Request.Headers) {
|
||||
converter.tCase.Steps[i].Request.Headers) {
|
||||
t.FailNow()
|
||||
}
|
||||
if !assert.Equal(t,
|
||||
map[string]string{"UserName": "debugtalk"},
|
||||
converter.tCase.TSteps[i].Request.Cookies) {
|
||||
converter.tCase.Steps[i].Request.Cookies) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func TestLoadHARWithProfileOverride(t *testing.T) {
|
||||
func TestMakeRequestWithProfile(t *testing.T) {
|
||||
caseConverter := &TCaseConverter{
|
||||
tCase: &hrp.TestCase{
|
||||
TSteps: []*hrp.TStep{
|
||||
Steps: []*hrp.TStep{
|
||||
{
|
||||
Request: &hrp.Request{
|
||||
Method: hrp.HTTPMethod("POST"),
|
||||
@@ -89,12 +89,12 @@ func TestMakeRequestWithProfile(t *testing.T) {
|
||||
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded", "User-Agent": "hrp",
|
||||
}, caseConverter.tCase.TSteps[0].Request.Headers) {
|
||||
}, caseConverter.tCase.Steps[0].Request.Headers) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"UserName": "debugtalk", "abc": "123",
|
||||
}, caseConverter.tCase.TSteps[0].Request.Cookies) {
|
||||
}, caseConverter.tCase.Steps[0].Request.Cookies) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func TestMakeRequestWithProfile(t *testing.T) {
|
||||
func TestMakeRequestWithProfileOverride(t *testing.T) {
|
||||
caseConverter := &TCaseConverter{
|
||||
tCase: &hrp.TestCase{
|
||||
TSteps: []*hrp.TStep{
|
||||
Steps: []*hrp.TStep{
|
||||
{
|
||||
Request: &hrp.Request{
|
||||
Method: hrp.HTTPMethod("POST"),
|
||||
@@ -131,12 +131,12 @@ func TestMakeRequestWithProfileOverride(t *testing.T) {
|
||||
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}, caseConverter.tCase.TSteps[0].Request.Headers) {
|
||||
}, caseConverter.tCase.Steps[0].Request.Headers) {
|
||||
t.Fatal()
|
||||
}
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"UserName": "debugtalk",
|
||||
}, caseConverter.tCase.TSteps[0].Request.Cookies) {
|
||||
}, caseConverter.tCase.Steps[0].Request.Cookies) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user