mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 00:39:34 +08:00
change: make genOutputPath public
This commit is contained in:
@@ -7,15 +7,16 @@ Convert HAR to json/yaml testcase files
|
|||||||
Convert HAR to json/yaml testcase files
|
Convert HAR to json/yaml testcase files
|
||||||
|
|
||||||
```
|
```
|
||||||
hrp har2case path... [flags]
|
hrp har2case harPath... [flags]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
-h, --help help for har2case
|
-h, --help help for har2case
|
||||||
-j, --to-json convert to JSON format (default)
|
-d, --output-dir string specify output directory, default to the same dir with har file
|
||||||
-y, --to-yaml convert to JSON format
|
-j, --to-json convert to JSON format (default)
|
||||||
|
-y, --to-yaml convert to JSON format
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ import (
|
|||||||
"github.com/httprunner/hrp"
|
"github.com/httprunner/hrp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
suffixJSON = ".json"
|
||||||
|
suffixYAML = ".yaml"
|
||||||
|
)
|
||||||
|
|
||||||
func NewHAR(path string) *HAR {
|
func NewHAR(path string) *HAR {
|
||||||
return &HAR{
|
return &HAR{
|
||||||
path: path,
|
path: path,
|
||||||
@@ -34,33 +39,21 @@ func (h *HAR) SetOutputDir(dir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *HAR) GenJSON() (jsonPath string, err error) {
|
func (h *HAR) GenJSON() (jsonPath string, err error) {
|
||||||
jsonFile := getFilenameWithoutExtension(h.path) + ".json"
|
|
||||||
if h.outputDir != "" {
|
|
||||||
jsonPath = filepath.Join(h.outputDir, jsonFile)
|
|
||||||
} else {
|
|
||||||
jsonPath = filepath.Join(filepath.Dir(h.path), jsonFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
tCase, err := h.makeTestCase()
|
tCase, err := h.makeTestCase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
jsonPath = h.genOutputPath(suffixJSON)
|
||||||
err = tCase.Dump2JSON(jsonPath)
|
err = tCase.Dump2JSON(jsonPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HAR) GenYAML() (yamlPath string, err error) {
|
func (h *HAR) GenYAML() (yamlPath string, err error) {
|
||||||
yamlFile := getFilenameWithoutExtension(h.path) + ".yaml"
|
|
||||||
if h.outputDir != "" {
|
|
||||||
yamlPath = filepath.Join(h.outputDir, yamlFile)
|
|
||||||
} else {
|
|
||||||
yamlPath = filepath.Join(filepath.Dir(h.path), yamlFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
tCase, err := h.makeTestCase()
|
tCase, err := h.makeTestCase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
yamlPath = h.genOutputPath(suffixYAML)
|
||||||
err = tCase.Dump2YAML(yamlPath)
|
err = tCase.Dump2YAML(yamlPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -306,6 +299,15 @@ func (s *TStep) makeValidate(entry *Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HAR) genOutputPath(suffix string) string {
|
||||||
|
file := getFilenameWithoutExtension(h.path) + suffix
|
||||||
|
if h.outputDir != "" {
|
||||||
|
return filepath.Join(h.outputDir, file)
|
||||||
|
} else {
|
||||||
|
return filepath.Join(filepath.Dir(h.path), file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getFilenameWithoutExtension(path string) string {
|
func getFilenameWithoutExtension(path string) string {
|
||||||
base := filepath.Base(path)
|
base := filepath.Base(path)
|
||||||
ext := filepath.Ext(base)
|
ext := filepath.Ext(base)
|
||||||
|
|||||||
Reference in New Issue
Block a user