mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: add --profile flag for har2case to support overwrite headers/cookies with specified yaml/json profile file
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
harPath = "../../../examples/hrp/har/demo.har"
|
||||
harPath2 = "../../../examples/hrp/har/postman-echo.har"
|
||||
harPath = "../../../examples/data/har/demo.har"
|
||||
harPath2 = "../../../examples/data/har/postman-echo.har"
|
||||
profilePath = "../../../examples/data/har/profile.yml"
|
||||
)
|
||||
|
||||
func TestGenJSON(t *testing.T) {
|
||||
@@ -47,6 +48,26 @@ func TestLoadHAR(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadHARWithProfile(t *testing.T) {
|
||||
har := NewHAR(harPath)
|
||||
har.SetProfile(profilePath)
|
||||
_, err := har.load()
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if !assert.Equal(t,
|
||||
map[string]interface{}{"Content-Type": "application/x-www-form-urlencoded"},
|
||||
har.profileJSON["headers"]) {
|
||||
t.Fail()
|
||||
}
|
||||
if !assert.Equal(t,
|
||||
map[string]interface{}{"UserName": "debugtalk"},
|
||||
har.profileJSON["cookies"]) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeTestCase(t *testing.T) {
|
||||
har := NewHAR(harPath)
|
||||
tCase, err := har.makeTestCase()
|
||||
@@ -115,12 +136,105 @@ func TestMakeTestCase(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFilenameWithoutExtension(t *testing.T) {
|
||||
filename := getFilenameWithoutExtension("../../../examples/hrp/har/postman-echo.har")
|
||||
filename := getFilenameWithoutExtension(harPath2)
|
||||
if !assert.Equal(t, "postman-echo", filename) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeRequestHeaders(t *testing.T) {
|
||||
har := NewHAR("")
|
||||
entry := &Entry{
|
||||
Request: Request{
|
||||
Method: "POST",
|
||||
Headers: []NVP{
|
||||
{Name: "Content-Type", Value: "application/json; charset=utf-8"},
|
||||
},
|
||||
},
|
||||
}
|
||||
step, err := har.prepareTestStep(entry)
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
}, step.Request.Headers) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeRequestHeadersWithProfile(t *testing.T) {
|
||||
har := NewHAR("")
|
||||
har.SetProfile(profilePath)
|
||||
entry := &Entry{
|
||||
Request: Request{
|
||||
Method: "POST",
|
||||
Headers: []NVP{
|
||||
{Name: "Content-Type", Value: "application/json; charset=utf-8"},
|
||||
},
|
||||
},
|
||||
}
|
||||
step, err := har.prepareTestStep(entry)
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
}, step.Request.Headers) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeRequestCookies(t *testing.T) {
|
||||
har := NewHAR("")
|
||||
entry := &Entry{
|
||||
Request: Request{
|
||||
Method: "POST",
|
||||
Cookies: []Cookie{
|
||||
{Name: "abc", Value: "123"},
|
||||
{Name: "UserName", Value: "leolee"},
|
||||
},
|
||||
},
|
||||
}
|
||||
step, err := har.prepareTestStep(entry)
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"abc": "123",
|
||||
"UserName": "leolee",
|
||||
}, step.Request.Cookies) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeRequestCookiesWithProfile(t *testing.T) {
|
||||
har := NewHAR("")
|
||||
har.SetProfile(profilePath)
|
||||
entry := &Entry{
|
||||
Request: Request{
|
||||
Method: "POST",
|
||||
Cookies: []Cookie{
|
||||
{Name: "abc", Value: "123"},
|
||||
{Name: "UserName", Value: "leolee"},
|
||||
},
|
||||
},
|
||||
}
|
||||
step, err := har.prepareTestStep(entry)
|
||||
if !assert.NoError(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if !assert.Equal(t, map[string]string{
|
||||
"UserName": "debugtalk",
|
||||
}, step.Request.Cookies) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeRequestDataParams(t *testing.T) {
|
||||
har := NewHAR("")
|
||||
entry := &Entry{
|
||||
|
||||
Reference in New Issue
Block a user