mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: add har2case flag
This commit is contained in:
@@ -4,7 +4,7 @@ One-stop solution for HTTP(S) testing.
|
||||
|
||||
### Synopsis
|
||||
|
||||
hrp (HttpRunnerPlus) is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨
|
||||
hrp (HttpRunner+) is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨
|
||||
|
||||
License: Apache-2.0
|
||||
Github: https://github.com/httprunner/hrp
|
||||
@@ -22,4 +22,4 @@ Copyright 2021 debugtalk
|
||||
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
|
||||
* [hrp run](hrp_run.md) - run API test
|
||||
|
||||
###### Auto generated by spf13/cobra on 16-Oct-2021
|
||||
###### Auto generated by spf13/cobra on 17-Oct-2021
|
||||
|
||||
@@ -37,4 +37,4 @@ hrp boom [flags]
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 16-Oct-2021
|
||||
###### Auto generated by spf13/cobra on 17-Oct-2021
|
||||
|
||||
@@ -13,11 +13,13 @@ hrp har2case path... [flags]
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for har2case
|
||||
-h, --help help for har2case
|
||||
-j, --to-json convert to JSON format (default)
|
||||
-y, --to-yaml convert to JSON format
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 16-Oct-2021
|
||||
###### Auto generated by spf13/cobra on 17-Oct-2021
|
||||
|
||||
@@ -30,4 +30,4 @@ hrp run path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 16-Oct-2021
|
||||
###### Auto generated by spf13/cobra on 17-Oct-2021
|
||||
|
||||
4694
examples/har/postman-echo.har
Normal file
4694
examples/har/postman-echo.har
Normal file
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@ import (
|
||||
var harPath string
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
harPath = "../examples/demo.har"
|
||||
harPath = "../examples/har/demo.har"
|
||||
|
||||
// run all tests
|
||||
code := m.Run()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -14,27 +13,34 @@ var har2caseCmd = &cobra.Command{
|
||||
Use: "har2case path...",
|
||||
Short: "Convert HAR to json/yaml testcase files",
|
||||
Long: `Convert HAR to json/yaml testcase files`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("har2case called")
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var outputFiles []string
|
||||
for _, arg := range args {
|
||||
jsonPath, _ := har2case.NewHAR(arg).GenJSON()
|
||||
outputFiles = append(outputFiles, jsonPath)
|
||||
var outputPath string
|
||||
var err error
|
||||
if genYAMLFlag {
|
||||
outputPath, err = har2case.NewHAR(arg).GenYAML()
|
||||
} else {
|
||||
outputPath, err = har2case.NewHAR(arg).GenJSON()
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outputFiles = append(outputFiles, outputPath)
|
||||
}
|
||||
log.Printf("%v", outputFiles)
|
||||
log.Printf("output: %v", outputFiles)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
genJSONFlag bool
|
||||
genYAMLFlag bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(har2caseCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// har2caseCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// har2caseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
har2caseCmd.Flags().BoolVarP(&genJSONFlag, "to-json", "j", false, "convert to JSON format (default)")
|
||||
har2caseCmd.Flags().BoolVarP(&genYAMLFlag, "to-yaml", "y", false, "convert to JSON format")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user