add unittest; add --patch options

This commit is contained in:
buyuxiang
2022-05-17 16:03:45 +08:00
parent dd9f8878b2
commit 76bf2309ed
18 changed files with 604 additions and 248 deletions
+22 -15
View File
@@ -6,7 +6,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp/internal/har2case"
"github.com/httprunner/httprunner/v4/hrp/internal/convert/har2case"
)
// har2caseCmd represents the har2case command
@@ -22,7 +22,7 @@ var har2caseCmd = &cobra.Command{
var outputFiles []string
for _, arg := range args {
// must choose one
if !genYAMLFlag && !genJSONFlag {
if !har2caseGenYAMLFlag && !har2caseGenJSONFlag {
return errors.New("please select convert format type")
}
var outputPath string
@@ -31,17 +31,22 @@ var har2caseCmd = &cobra.Command{
har := har2case.NewHAR(arg)
// specify output dir
if outputDir != "" {
har.SetOutputDir(outputDir)
if har2caseOutputDir != "" {
har.SetOutputDir(har2caseOutputDir)
}
// specify profile
if profilePath != "" {
har.SetProfile(profilePath)
if har2caseProfilePath != "" {
har.SetProfile(har2caseProfilePath)
}
// specify profile
if har2casePatchPath != "" {
har.SetPatch(har2casePatchPath)
}
// generate json/yaml files
if genYAMLFlag {
if har2caseGenYAMLFlag {
outputPath, err = har.GenYAML()
} else {
outputPath, err = har.GenJSON() // default
@@ -57,16 +62,18 @@ var har2caseCmd = &cobra.Command{
}
var (
genJSONFlag bool
genYAMLFlag bool
outputDir string
profilePath string
har2caseGenJSONFlag bool
har2caseGenYAMLFlag bool
har2caseOutputDir string
har2caseProfilePath string
har2casePatchPath string
)
func init() {
rootCmd.AddCommand(har2caseCmd)
har2caseCmd.Flags().BoolVarP(&genJSONFlag, "to-json", "j", true, "convert to JSON format")
har2caseCmd.Flags().BoolVarP(&genYAMLFlag, "to-yaml", "y", false, "convert to YAML format")
har2caseCmd.Flags().StringVarP(&outputDir, "output-dir", "d", "", "specify output directory, default to the same dir with har file")
har2caseCmd.Flags().StringVarP(&profilePath, "profile", "p", "", "specify profile path to override headers and cookies")
har2caseCmd.Flags().BoolVarP(&har2caseGenJSONFlag, "to-json", "j", true, "convert to JSON format")
har2caseCmd.Flags().BoolVarP(&har2caseGenYAMLFlag, "to-yaml", "y", false, "convert to YAML format")
har2caseCmd.Flags().StringVarP(&har2caseOutputDir, "output-dir", "d", "", "specify output directory, default to the same dir with har file")
har2caseCmd.Flags().StringVarP(&har2caseProfilePath, "profile", "p", "", "specify profile path to override headers and cookies")
har2caseCmd.Flags().StringVarP(&har2casePatchPath, "patch", "r", "", "specify the path of the file used to replace headers and cookies")
}