mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
set DisableFlagParsing: true
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
- feat: support omitting websocket url if not necessary
|
- feat: support omitting websocket url if not necessary
|
||||||
- feat: support multiple websocket connections each session
|
- feat: support multiple websocket connections each session
|
||||||
- fix: optimize websocket step initialization
|
- fix: optimize websocket step initialization
|
||||||
|
- feat: support convert curl command(s) to testcase(s)
|
||||||
|
- feat: support run curl as subcommand of run/boom/convert
|
||||||
|
|
||||||
## v4.1.6 (2022-07-04)
|
## v4.1.6 (2022-07-04)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -37,4 +37,4 @@ Copyright 2017 debugtalk
|
|||||||
* [hrp startproject](hrp_startproject.md) - create a scaffold project
|
* [hrp startproject](hrp_startproject.md) - create a scaffold project
|
||||||
* [hrp wiki](hrp_wiki.md) - visit https://httprunner.com
|
* [hrp wiki](hrp_wiki.md) - visit https://httprunner.com
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -41,6 +41,6 @@ hrp boom [flags]
|
|||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
* [hrp boom curl](hrp_boom_curl.md) - run load test with boomer using converted curl testcase
|
* [hrp boom curl](hrp_boom_curl.md) - run load test with boomer by curl command
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## hrp boom curl
|
## hrp boom curl
|
||||||
|
|
||||||
run load test with boomer using converted curl testcase
|
run load test with boomer by curl command
|
||||||
|
|
||||||
```
|
```
|
||||||
hrp boom curl URLs [flags]
|
hrp boom curl URLs [flags]
|
||||||
@@ -9,18 +9,11 @@ hrp boom curl URLs [flags]
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
-b, --cookie strings -b, --cookie in curl
|
-h, --help help for curl
|
||||||
-d, --data strings -d, --data in curl
|
|
||||||
-F, --form strings -F, --form in curl
|
|
||||||
-G, --get -G, --get in curl
|
|
||||||
-I, --head -I, --head in curl
|
|
||||||
-H, --header strings -H, --header in curl
|
|
||||||
-h, --help help for curl
|
|
||||||
-X, --request string -X, --request in curl
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [hrp boom](hrp_boom.md) - run load test with boomer
|
* [hrp boom](hrp_boom.md) - run load test with boomer
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ hrp build $path ... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ hrp convert $path... [flags]
|
|||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
* [hrp convert curl](hrp_convert_curl.md) - convert curl command(s) to httprunner testcase
|
* [hrp convert curl](hrp_convert_curl.md) - convert curl command to httprunner testcase
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## hrp convert curl
|
## hrp convert curl
|
||||||
|
|
||||||
convert curl command(s) to httprunner testcase
|
convert curl command to httprunner testcase
|
||||||
|
|
||||||
```
|
```
|
||||||
hrp convert curl URLs [flags]
|
hrp convert curl URLs [flags]
|
||||||
@@ -9,18 +9,11 @@ hrp convert curl URLs [flags]
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
-b, --cookie strings -b, --cookie in curl
|
-h, --help help for curl
|
||||||
-d, --data strings -d, --data in curl
|
|
||||||
-F, --form strings -F, --form in curl
|
|
||||||
-G, --get -G, --get in curl
|
|
||||||
-I, --head -I, --head in curl
|
|
||||||
-H, --header strings -H, --header in curl
|
|
||||||
-h, --help help for curl
|
|
||||||
-X, --request string -X, --request in curl
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases
|
* [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
## hrp har2case
|
|
||||||
|
|
||||||
convert HAR to json/yaml testcase files
|
|
||||||
|
|
||||||
### Synopsis
|
|
||||||
|
|
||||||
convert HAR to json/yaml testcase files
|
|
||||||
|
|
||||||
```
|
|
||||||
hrp har2case $har_path... [flags]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Options
|
|
||||||
|
|
||||||
```
|
|
||||||
-h, --help help for har2case
|
|
||||||
-d, --output-dir string specify output directory, default to the same dir with har file
|
|
||||||
-p, --profile string specify profile path to override headers and cookies
|
|
||||||
-j, --to-json convert to JSON format (default)
|
|
||||||
-y, --to-yaml convert to YAML format
|
|
||||||
```
|
|
||||||
|
|
||||||
### SEE ALSO
|
|
||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 29-May-2022
|
|
||||||
@@ -16,4 +16,4 @@ hrp pytest $path ... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
+2
-2
@@ -34,6 +34,6 @@ hrp run $path... [flags]
|
|||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
* [hrp run curl](hrp_run_curl.md) - run API test with go engine using converted curl testcase
|
* [hrp run curl](hrp_run_curl.md) - run API test with go engine by curl command
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## hrp run curl
|
## hrp run curl
|
||||||
|
|
||||||
run API test with go engine using converted curl testcase
|
run API test with go engine by curl command
|
||||||
|
|
||||||
```
|
```
|
||||||
hrp run curl URLs [flags]
|
hrp run curl URLs [flags]
|
||||||
@@ -9,18 +9,11 @@ hrp run curl URLs [flags]
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
-b, --cookie strings -b, --cookie in curl
|
-h, --help help for curl
|
||||||
-d, --data strings -d, --data in curl
|
|
||||||
-F, --form strings -F, --form in curl
|
|
||||||
-G, --get -G, --get in curl
|
|
||||||
-I, --head -I, --head in curl
|
|
||||||
-H, --header strings -H, --header in curl
|
|
||||||
-h, --help help for curl
|
|
||||||
-X, --request string -X, --request in curl
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|
||||||
* [hrp run](hrp_run.md) - run API test with go engine
|
* [hrp run](hrp_run.md) - run API test with go engine
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -21,4 +21,4 @@ hrp startproject $project_name [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ hrp wiki [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 6-Jul-2022
|
###### Auto generated by spf13/cobra on 22-Jul-2022
|
||||||
|
|||||||
+23
-64
@@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -13,9 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var runCurlCmd = &cobra.Command{
|
var runCurlCmd = &cobra.Command{
|
||||||
Use: "curl URLs",
|
Use: "curl URLs",
|
||||||
Short: "run API test with go engine by curl command",
|
Short: "run API test with go engine by curl command",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
DisableFlagParsing: true,
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
setLogLevel(logLevel)
|
setLogLevel(logLevel)
|
||||||
},
|
},
|
||||||
@@ -28,11 +30,12 @@ var runCurlCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var boomCurlCmd = &cobra.Command{
|
var boomCurlCmd = &cobra.Command{
|
||||||
Use: "curl URLs",
|
Use: "curl URLs",
|
||||||
Short: "run load test with boomer by curl command",
|
Short: "run load test with boomer by curl command",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
DisableFlagParsing: true,
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
boomer.SetUlimit(10240) // ulimit -n 10240
|
boomer.SetUlimit(10240)
|
||||||
if !strings.EqualFold(logLevel, "DEBUG") {
|
if !strings.EqualFold(logLevel, "DEBUG") {
|
||||||
logLevel = "WARN" // disable info logs for load testing
|
logLevel = "WARN" // disable info logs for load testing
|
||||||
}
|
}
|
||||||
@@ -45,9 +48,10 @@ var boomCurlCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var convertCurlCmd = &cobra.Command{
|
var convertCurlCmd = &cobra.Command{
|
||||||
Use: "curl URLs",
|
Use: "curl URLs",
|
||||||
Short: "convert curl command to httprunner testcase",
|
Short: "convert curl command to httprunner testcase",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
DisableFlagParsing: true,
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
setLogLevel(logLevel)
|
setLogLevel(logLevel)
|
||||||
},
|
},
|
||||||
@@ -57,35 +61,10 @@ var convertCurlCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
cookieSlice []string
|
|
||||||
dataSlice []string
|
|
||||||
formSlice []string
|
|
||||||
get bool
|
|
||||||
head bool
|
|
||||||
headerSlice []string
|
|
||||||
request string
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runCmd.AddCommand(runCurlCmd)
|
runCmd.AddCommand(runCurlCmd)
|
||||||
addCurlFlags(runCurlCmd)
|
|
||||||
|
|
||||||
boomCmd.AddCommand(boomCurlCmd)
|
boomCmd.AddCommand(boomCurlCmd)
|
||||||
addCurlFlags(boomCurlCmd)
|
|
||||||
|
|
||||||
convertCmd.AddCommand(convertCurlCmd)
|
convertCmd.AddCommand(convertCurlCmd)
|
||||||
addCurlFlags(convertCurlCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func addCurlFlags(cmd *cobra.Command) {
|
|
||||||
cmd.Flags().StringSliceVarP(&cookieSlice, "cookie", "b", nil, "-b, --cookie in curl")
|
|
||||||
cmd.Flags().StringSliceVarP(&dataSlice, "data", "d", nil, "-d, --data in curl")
|
|
||||||
cmd.Flags().StringSliceVarP(&formSlice, "form", "F", nil, "-F, --form in curl")
|
|
||||||
cmd.Flags().BoolVarP(&get, "get", "G", false, "-G, --get in curl")
|
|
||||||
cmd.Flags().BoolVarP(&head, "head", "I", false, "-I, --head in curl")
|
|
||||||
cmd.Flags().StringSliceVarP(&headerSlice, "header", "H", nil, "-H, --header in curl")
|
|
||||||
cmd.Flags().StringVarP(&request, "request", "X", "", "-X, --request in curl")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCurlTestCase(args []string) *hrp.TestCase {
|
func makeCurlTestCase(args []string) *hrp.TestCase {
|
||||||
@@ -95,11 +74,7 @@ func makeCurlTestCase(args []string) *hrp.TestCase {
|
|||||||
log.Error().Err(err).Msg("convert curl command failed")
|
log.Error().Err(err).Msg("convert curl command failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
casePath, err := os.Getwd()
|
casePath, _ := os.Getwd()
|
||||||
if err != nil {
|
|
||||||
casePath = ""
|
|
||||||
log.Error().Err(err).Msg("get working directory failed")
|
|
||||||
}
|
|
||||||
testCase, err := tCase.ToTestCase(casePath)
|
testCase, err := tCase.ToTestCase(casePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("convert testcase to failed")
|
log.Error().Err(err).Msg("convert testcase to failed")
|
||||||
@@ -109,29 +84,13 @@ func makeCurlTestCase(args []string) *hrp.TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeCurlCommand(args []string) string {
|
func makeCurlCommand(args []string) string {
|
||||||
var cmdList []string
|
for i := 0; i < len(args); i++ {
|
||||||
cmdList = append(cmdList, "curl")
|
if !strings.HasPrefix(args[i], "-") {
|
||||||
for _, c := range cookieSlice {
|
args[i] = fmt.Sprintf("\"%s\"", args[i])
|
||||||
cmdList = append(cmdList, "--cookie", c)
|
}
|
||||||
}
|
}
|
||||||
for _, d := range dataSlice {
|
var curlCmd []string
|
||||||
cmdList = append(cmdList, "--data", d)
|
curlCmd = append(curlCmd, "curl")
|
||||||
}
|
curlCmd = append(curlCmd, args...)
|
||||||
for _, f := range formSlice {
|
return strings.Join(curlCmd, " ")
|
||||||
cmdList = append(cmdList, "--form", f)
|
|
||||||
}
|
|
||||||
if get {
|
|
||||||
cmdList = append(cmdList, "--get")
|
|
||||||
}
|
|
||||||
if head {
|
|
||||||
cmdList = append(cmdList, "--head")
|
|
||||||
}
|
|
||||||
for _, h := range headerSlice {
|
|
||||||
cmdList = append(cmdList, "--header", h)
|
|
||||||
}
|
|
||||||
if request != "" {
|
|
||||||
cmdList = append(cmdList, "--request", request)
|
|
||||||
}
|
|
||||||
cmdList = append(cmdList, args...)
|
|
||||||
return strings.Join(cmdList, " ")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,22 +104,22 @@ func Run(outputType OutputType, outputDir, profilePath string, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadTCase loads source file and convert to TCase type
|
// LoadTCase loads source file and convert to TCase type
|
||||||
func LoadTCase(path string) (*hrp.TCase, error) {
|
func LoadTCase(inputSample string) (*hrp.TCase, error) {
|
||||||
if strings.HasPrefix(path, "curl ") {
|
if strings.HasPrefix(inputSample, "curl ") {
|
||||||
// 'path' contains curl command
|
// 'path' contains curl command
|
||||||
curlCase, err := LoadSingleCurlCase(path)
|
curlCase, err := LoadSingleCurlCase(inputSample)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return curlCase, nil
|
return curlCase, nil
|
||||||
}
|
}
|
||||||
extName := filepath.Ext(path)
|
extName := filepath.Ext(inputSample)
|
||||||
if extName == "" {
|
if extName == "" {
|
||||||
return nil, errors.New("file extension is not specified")
|
return nil, errors.New("file extension is not specified")
|
||||||
}
|
}
|
||||||
switch extName {
|
switch extName {
|
||||||
case ".har":
|
case ".har":
|
||||||
tCase, err := LoadHARCase(path)
|
tCase, err := LoadHARCase(inputSample)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -127,19 +127,19 @@ func LoadTCase(path string) (*hrp.TCase, error) {
|
|||||||
case ".json":
|
case ".json":
|
||||||
// priority: hrp JSON case > postman > swagger
|
// priority: hrp JSON case > postman > swagger
|
||||||
// check if hrp JSON case
|
// check if hrp JSON case
|
||||||
tCase, err := LoadJSONCase(path)
|
tCase, err := LoadJSONCase(inputSample)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return tCase, nil
|
return tCase, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if postman format
|
// check if postman format
|
||||||
casePostman, err := LoadPostmanCase(path)
|
casePostman, err := LoadPostmanCase(inputSample)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return casePostman, nil
|
return casePostman, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if swagger format
|
// check if swagger format
|
||||||
caseSwagger, err := LoadSwaggerCase(path)
|
caseSwagger, err := LoadSwaggerCase(inputSample)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return caseSwagger, nil
|
return caseSwagger, nil
|
||||||
}
|
}
|
||||||
@@ -148,13 +148,13 @@ func LoadTCase(path string) (*hrp.TCase, error) {
|
|||||||
case ".yaml", ".yml":
|
case ".yaml", ".yml":
|
||||||
// priority: hrp YAML case > swagger
|
// priority: hrp YAML case > swagger
|
||||||
// check if hrp YAML case
|
// check if hrp YAML case
|
||||||
tCase, err := NewYAMLCase(path)
|
tCase, err := NewYAMLCase(inputSample)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return tCase, nil
|
return tCase, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if swagger format
|
// check if swagger format
|
||||||
caseSwagger, err := LoadSwaggerCase(path)
|
caseSwagger, err := LoadSwaggerCase(inputSample)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return caseSwagger, nil
|
return caseSwagger, nil
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ func LoadTCase(path string) (*hrp.TCase, error) {
|
|||||||
case ".jmx": // TODO
|
case ".jmx": // TODO
|
||||||
return nil, errors.New("convert JMeter jmx is not implemented")
|
return nil, errors.New("convert JMeter jmx is not implemented")
|
||||||
case ".txt":
|
case ".txt":
|
||||||
curlCase, err := LoadCurlCase(path)
|
curlCase, err := LoadCurlCase(inputSample)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -186,16 +186,12 @@ type TCaseConverter struct {
|
|||||||
|
|
||||||
func (c *TCaseConverter) genOutputPath(suffix string) string {
|
func (c *TCaseConverter) genOutputPath(suffix string) string {
|
||||||
var outFileFullName string
|
var outFileFullName string
|
||||||
if curlCmd := strings.TrimSpace(c.InputSample); strings.HasPrefix(curlCmd, "curl") {
|
if curlCmd := strings.TrimSpace(c.InputSample); strings.HasPrefix(curlCmd, "curl ") {
|
||||||
outFileFullName = fmt.Sprintf("curl_%v_test%v", time.Now().Format("20060102150405"), suffix)
|
outFileFullName = fmt.Sprintf("curl_%v_test%v", time.Now().Format("20060102150405"), suffix)
|
||||||
if c.OutputDir != "" {
|
if c.OutputDir != "" {
|
||||||
return filepath.Join(c.OutputDir, outFileFullName)
|
return filepath.Join(c.OutputDir, outFileFullName)
|
||||||
} else {
|
} else {
|
||||||
curWorkDir, err := os.Getwd()
|
curWorkDir, _ := os.Getwd()
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("get current working direction failed")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return filepath.Join(curWorkDir, outFileFullName)
|
return filepath.Join(curWorkDir, outFileFullName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,9 +198,9 @@ func parseCaseCurl(cmd string) (CaseCurl, error) {
|
|||||||
|
|
||||||
type CaseCurl map[string][]string
|
type CaseCurl map[string][]string
|
||||||
|
|
||||||
// GetByIndex gets the value by index associated with the given key.
|
// Get gets the first value associated with the given key.
|
||||||
// If there are no value by index associated with the key, GetByIndex returns the empty string.
|
// If there are no values associated with the key, Get returns the empty string.
|
||||||
func (c CaseCurl) GetByIndex(key string, index int) string {
|
func (c CaseCurl) Get(key string, index int) string {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ type stepFromCurl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepFromCurl) makeRequestName(c CaseCurl) error {
|
func (s *stepFromCurl) makeRequestName(c CaseCurl) error {
|
||||||
s.Name = c.GetByIndex(originCmdKey, 0)
|
s.Name = c.Get(originCmdKey, 0)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ func (s *stepFromCurl) makeRequestMethod(c CaseCurl) error {
|
|||||||
s.Request.Method = http.MethodHead
|
s.Request.Method = http.MethodHead
|
||||||
}
|
}
|
||||||
if c.HaveKey("--request") {
|
if c.HaveKey("--request") {
|
||||||
s.Request.Method = hrp.HTTPMethod(strings.ToUpper(c.GetByIndex("--request", 0)))
|
s.Request.Method = hrp.HTTPMethod(strings.ToUpper(c.Get("--request", 0)))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -375,8 +375,6 @@ func (s *stepFromCurl) makeRequestHeader(headerExpr string) error {
|
|||||||
var headerValue string
|
var headerValue string
|
||||||
if i < len(headerExpr)-1 {
|
if i < len(headerExpr)-1 {
|
||||||
headerValue = strings.TrimSpace(headerExpr[i+1:])
|
headerValue = strings.TrimSpace(headerExpr[i+1:])
|
||||||
} else {
|
|
||||||
headerValue = ""
|
|
||||||
}
|
}
|
||||||
if strings.ToLower(headerKey) == "host" {
|
if strings.ToLower(headerKey) == "host" {
|
||||||
// headerExpr modifying internal header like "Host:"
|
// headerExpr modifying internal header like "Host:"
|
||||||
@@ -433,8 +431,6 @@ func (s *stepFromCurl) makeRequestCookie(cookieExpr string) error {
|
|||||||
var cookieValue string
|
var cookieValue string
|
||||||
if i < len(cookie)-1 {
|
if i < len(cookie)-1 {
|
||||||
cookieValue = strings.TrimSpace(cookie[i+1:])
|
cookieValue = strings.TrimSpace(cookie[i+1:])
|
||||||
} else {
|
|
||||||
cookieValue = ""
|
|
||||||
}
|
}
|
||||||
s.Request.Cookies[cookieKey] = cookieValue
|
s.Request.Cookies[cookieKey] = cookieValue
|
||||||
}
|
}
|
||||||
@@ -497,11 +493,8 @@ func (s *stepFromCurl) makeRequestForm(formList []string) error {
|
|||||||
var formValue string
|
var formValue string
|
||||||
if i < len(formExpr)-1 {
|
if i < len(formExpr)-1 {
|
||||||
formValue = strings.TrimSpace(formExpr[i+1:])
|
formValue = strings.TrimSpace(formExpr[i+1:])
|
||||||
} else {
|
|
||||||
formValue = ""
|
|
||||||
}
|
}
|
||||||
filePath := strings.TrimLeft(formValue, "@")
|
s.Request.Upload[formKey] = strings.Trim(formValue, "\"")
|
||||||
s.Request.Upload[formKey] = strings.Trim(filePath, "\"")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ func TestLoadCurlCase(t *testing.T) {
|
|||||||
// curl -F "dummyName=dummyFile" -F file1=@file1.txt -F file2=@file2.txt https://httpbin.org/post
|
// curl -F "dummyName=dummyFile" -F file1=@file1.txt -F file2=@file2.txt https://httpbin.org/post
|
||||||
if !assert.Equal(t, map[string]interface{}{
|
if !assert.Equal(t, map[string]interface{}{
|
||||||
"dummyName": "dummyFile",
|
"dummyName": "dummyFile",
|
||||||
"file1": "file1.txt",
|
"file1": "@file1.txt",
|
||||||
"file2": "file2.txt",
|
"file2": "@file2.txt",
|
||||||
}, tCase.TestSteps[3].Request.Upload) {
|
}, tCase.TestSteps[3].Request.Upload) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user