mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
change: remove har2case, move all features to go version
This commit is contained in:
@@ -140,8 +140,6 @@ func (tc *TCase) ToTestCase() (*TestCase, error) {
|
||||
return testCase, nil
|
||||
}
|
||||
|
||||
var ErrUnsupportedFileExt = fmt.Errorf("unsupported testcase file extension")
|
||||
|
||||
// APIPath implements IAPI interface.
|
||||
type APIPath string
|
||||
|
||||
|
||||
@@ -231,6 +231,7 @@ func Interface2Float64(i interface{}) (float64, error) {
|
||||
|
||||
var ErrUnsupportedFileExt = fmt.Errorf("unsupported file extension")
|
||||
|
||||
// LoadFile loads file content with file extension and assigns to structObj
|
||||
func LoadFile(path string, structObj interface{}) (err error) {
|
||||
log.Info().Str("path", path).Msg("load file")
|
||||
file, err := readFile(path)
|
||||
|
||||
@@ -29,17 +29,17 @@ func NewHAR(path string) *har {
|
||||
}
|
||||
|
||||
type har struct {
|
||||
path string
|
||||
filterStr string
|
||||
excludeStr string
|
||||
profileJSON map[string]interface{}
|
||||
outputDir string
|
||||
path string
|
||||
filterStr string
|
||||
excludeStr string
|
||||
profile map[string]interface{}
|
||||
outputDir string
|
||||
}
|
||||
|
||||
func (h *har) SetProfile(path string) {
|
||||
log.Info().Str("path", path).Msg("set profile")
|
||||
h.profileJSON = make(map[string]interface{})
|
||||
err := builtin.LoadFile(path, h.profileJSON)
|
||||
h.profile = make(map[string]interface{})
|
||||
err := builtin.LoadFile(path, h.profile)
|
||||
if err != nil {
|
||||
log.Warn().Str("path", path).
|
||||
Msg("invalid profile format, ignore!")
|
||||
@@ -145,7 +145,7 @@ func (h *har) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
|
||||
Request: &hrp.Request{},
|
||||
Validators: make([]interface{}, 0),
|
||||
},
|
||||
profileJSON: h.profileJSON,
|
||||
profile: h.profile,
|
||||
}
|
||||
if err := step.makeRequestMethod(entry); err != nil {
|
||||
return nil, err
|
||||
@@ -173,7 +173,7 @@ func (h *har) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
|
||||
|
||||
type tStep struct {
|
||||
hrp.TStep
|
||||
profileJSON map[string]interface{}
|
||||
profile map[string]interface{}
|
||||
}
|
||||
|
||||
func (s *tStep) makeRequestMethod(entry *Entry) error {
|
||||
@@ -201,7 +201,7 @@ func (s *tStep) makeRequestParams(entry *Entry) error {
|
||||
|
||||
func (s *tStep) makeRequestCookies(entry *Entry) error {
|
||||
s.Request.Cookies = make(map[string]string)
|
||||
cookies, ok := s.profileJSON["cookies"]
|
||||
cookies, ok := s.profile["cookies"]
|
||||
if ok {
|
||||
// use cookies from profile
|
||||
cookies, ok := cookies.(map[string]interface{})
|
||||
@@ -224,7 +224,7 @@ func (s *tStep) makeRequestCookies(entry *Entry) error {
|
||||
|
||||
func (s *tStep) makeRequestHeaders(entry *Entry) error {
|
||||
s.Request.Headers = make(map[string]string)
|
||||
headers, ok := s.profileJSON["headers"]
|
||||
headers, ok := s.profile["headers"]
|
||||
if ok {
|
||||
// use headers from profile
|
||||
cookies, ok := headers.(map[string]interface{})
|
||||
|
||||
@@ -58,12 +58,12 @@ func TestLoadHARWithProfile(t *testing.T) {
|
||||
|
||||
if !assert.Equal(t,
|
||||
map[string]interface{}{"Content-Type": "application/x-www-form-urlencoded"},
|
||||
har.profileJSON["headers"]) {
|
||||
har.profile["headers"]) {
|
||||
t.Fail()
|
||||
}
|
||||
if !assert.Equal(t,
|
||||
map[string]interface{}{"UserName": "debugtalk"},
|
||||
har.profileJSON["cookies"]) {
|
||||
har.profile["cookies"]) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user