mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 05:20:06 +08:00
fix: unittest
This commit is contained in:
@@ -2,20 +2,10 @@ curl httpbin.org
|
||||
|
||||
curl https://httpbin.org/get?key1=value1&key2=value2
|
||||
|
||||
curl -H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" \
|
||||
-d '{"type":"A","name":"www","data":"162.10.66.0","priority":null,"port":null,"weight":null}' \
|
||||
"https://httpbin.org/post"
|
||||
curl -H "Content-Type: application/json" -H "Authorization: Bearer b7d03a6947b217efb6f3ec3bd3504582" -d '{"type":"A","name":"www","data":"162.10.66.0","priority":null,"port":null,"weight":null}' "https://httpbin.org/post"
|
||||
|
||||
curl -F "dummyName=dummyFile" -F file1=@file1.txt -F file2=@file2.txt https://httpbin.org/post
|
||||
|
||||
curl https://httpbin.org/post \
|
||||
-d 'shipment[to_address][id]=adr_HrBKVA85' \
|
||||
-d 'shipment[from_address][id]=adr_VtuTOj7o' \
|
||||
-d 'shipment[parcel][id]=prcl_WDv2VzHp' \
|
||||
-d 'shipment[is_return]=true' \
|
||||
-d 'shipment[customs_info][id]=cstinfo_bl5sE20Y'
|
||||
|
||||
curl https://httpbing.org/post -H "Content-Type: application/x-www-form-urlencoded" \
|
||||
--data "key1=value+1&key2=value%3A2"
|
||||
curl https://httpbin.org/post -d 'shipment[to_address][id]=adr_HrBKVA85' -d 'shipment[from_address][id]=adr_VtuTOj7o' -d 'shipment[parcel][id]=prcl_WDv2VzHp' -d 'shipment[is_return]=true' -d 'shipment[customs_info][id]=cstinfo_bl5sE20Y'
|
||||
|
||||
curl https://httpbing.org/post -H "Content-Type: application/x-www-form-urlencoded" --data "key1=value+1&key2=value%3A2"
|
||||
|
||||
@@ -2,10 +2,13 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
"github.com/httprunner/httprunner/v4/hrp/pkg/convert"
|
||||
@@ -55,12 +58,35 @@ var convertCmd = &cobra.Command{
|
||||
log.Info().Str("outputType", outputType.String()).Msg("set default")
|
||||
}
|
||||
|
||||
var files []string
|
||||
for _, arg := range args {
|
||||
if err := caseConverter.Convert(arg, fromType, outputType); err != nil {
|
||||
log.Error().Err(err).Str("path", arg).
|
||||
if builtin.IsFolderPathExists(arg) {
|
||||
fs, err := ioutil.ReadDir(arg)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("path", arg).Msg("read dir failed")
|
||||
continue
|
||||
}
|
||||
for _, f := range fs {
|
||||
files = append(files, filepath.Join(arg, f.Name()))
|
||||
}
|
||||
} else {
|
||||
files = append(files, arg)
|
||||
}
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
extName := filepath.Ext(file)
|
||||
if !builtin.Contains(fromType.Extensions(), extName) {
|
||||
log.Warn().Str("path", file).
|
||||
Strs("expectExtensions", fromType.Extensions()).
|
||||
Msg("skip file")
|
||||
continue
|
||||
}
|
||||
|
||||
if err := caseConverter.Convert(file, fromType, outputType); err != nil {
|
||||
log.Error().Err(err).Str("path", file).
|
||||
Str("outputType", outputType.String()).
|
||||
Msg("convert case failed")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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