mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 09:49:33 +08:00
fix: unittest
This commit is contained in:
@@ -330,17 +330,29 @@ func (s *stepFromPostman) makeRequestBodyRaw(item *TItem) (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
languageType := "text"
|
||||
iOptions := item.Request.Body.Options
|
||||
if iOptions != nil {
|
||||
iLanguage := iOptions.(map[string]interface{})["raw"]
|
||||
if iLanguage != nil {
|
||||
languageType = iLanguage.(map[string]interface{})["language"].(string)
|
||||
}
|
||||
}
|
||||
|
||||
s.Request.Body = item.Request.Body.Raw
|
||||
contentType := s.Request.Headers["Content-Type"]
|
||||
if strings.Contains(contentType, "application/json") {
|
||||
if strings.Contains(contentType, "application/json") || languageType == "json" {
|
||||
var iBody interface{}
|
||||
err = json.Unmarshal([]byte(item.Request.Body.Raw), &iBody)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("33333")
|
||||
return errors.Wrap(err, "make request body (raw -> json) failed")
|
||||
}
|
||||
s.Request.Body = iBody
|
||||
}
|
||||
|
||||
if contentType == "" {
|
||||
s.Request.Headers["Content-Type"] = contentTypeMap[languageType]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ const (
|
||||
suffixYAML = ".yaml"
|
||||
suffixGoTest = ".go"
|
||||
suffixPyTest = ".py"
|
||||
suffixHAR = ".har"
|
||||
)
|
||||
|
||||
type FromType int
|
||||
@@ -54,6 +55,25 @@ func (fromType FromType) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (fromType FromType) Extensions() []string {
|
||||
switch fromType {
|
||||
case FromTypeYAML:
|
||||
return []string{suffixYAML, ".yml"}
|
||||
case FromTypeHAR:
|
||||
return []string{suffixHAR}
|
||||
case FromTypePostman, FromTypeSwagger:
|
||||
return []string{suffixJSON}
|
||||
case FromTypeCurl:
|
||||
return []string{".txt", ".curl"}
|
||||
case FromTypeGotest:
|
||||
return []string{suffixGoTest}
|
||||
case FromTypePyest:
|
||||
return []string{suffixPyTest}
|
||||
default:
|
||||
return []string{suffixJSON}
|
||||
}
|
||||
}
|
||||
|
||||
type OutputType int
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user