mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 09:19:41 +08:00
fix: modify logic of generating empty project
This commit is contained in:
@@ -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 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-2022
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ hrp boom [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-2022
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ hrp convert $path... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-2022
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ hrp har2case $har_path... [flags]
|
|||||||
-h, --help help for har2case
|
-h, --help help for har2case
|
||||||
-d, --output-dir string specify output directory, default to the same dir with har file
|
-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
|
-p, --profile string specify profile path to override headers and cookies
|
||||||
-j, --to-json convert to JSON format (default true)
|
-j, --to-json convert to JSON format (default)
|
||||||
-y, --to-yaml convert to YAML format
|
-y, --to-yaml convert to YAML format
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -24,4 +24,4 @@ hrp har2case $har_path... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 25-May-2022
|
###### Auto generated by spf13/cobra on 26-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 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-2022
|
||||||
|
|||||||
@@ -35,4 +35,4 @@ hrp run $path... [flags]
|
|||||||
|
|
||||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-2022
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ hrp startproject $project_name [flags]
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
|
--empty generate empty project
|
||||||
-f, --force force to overwrite existing project
|
-f, --force force to overwrite existing project
|
||||||
--go generate hashicorp go plugin
|
--go generate hashicorp go plugin
|
||||||
-h, --help help for startproject
|
-h, --help help for startproject
|
||||||
@@ -20,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 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-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 25-May-2022
|
###### Auto generated by spf13/cobra on 26-May-2022
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"project_name": "demo-with-go-plugin",
|
"project_name": "demo-with-go-plugin",
|
||||||
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin",
|
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin",
|
||||||
"create_time": "2022-05-26T20:08:49.164545+08:00",
|
"create_time": "2022-05-26T22:08:10.455301+08:00",
|
||||||
"hrp_version": "v4.1.0-beta"
|
"hrp_version": "v4.1.0-beta"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"project_name": "demo-with-py-plugin",
|
"project_name": "demo-with-py-plugin",
|
||||||
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin",
|
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin",
|
||||||
"create_time": "2022-05-26T20:08:56.909632+08:00",
|
"create_time": "2022-05-26T22:08:18.580462+08:00",
|
||||||
"hrp_version": "v4.1.0-beta"
|
"hrp_version": "v4.1.0-beta"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"project_name": "demo-without-plugin",
|
"project_name": "demo-without-plugin",
|
||||||
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin",
|
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin",
|
||||||
"create_time": "2022-05-26T20:08:57.501166+08:00",
|
"create_time": "2022-05-26T22:08:19.331271+08:00",
|
||||||
"hrp_version": "v4.1.0-beta"
|
"hrp_version": "v4.1.0-beta"
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,9 @@ var scaffoldCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pluginType scaffold.PluginType
|
var pluginType scaffold.PluginType
|
||||||
if ignorePlugin {
|
if empty {
|
||||||
|
pluginType = scaffold.Empty
|
||||||
|
} else if ignorePlugin {
|
||||||
pluginType = scaffold.Ignore
|
pluginType = scaffold.Ignore
|
||||||
} else if genGoPlugin {
|
} else if genGoPlugin {
|
||||||
pluginType = scaffold.Go
|
pluginType = scaffold.Go
|
||||||
@@ -32,7 +34,7 @@ var scaffoldCmd = &cobra.Command{
|
|||||||
pluginType = scaffold.Py // default
|
pluginType = scaffold.Py // default
|
||||||
}
|
}
|
||||||
|
|
||||||
err := scaffold.CreateScaffold(args[0], pluginType, empty, force)
|
err := scaffold.CreateScaffold(args[0], pluginType, force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("create scaffold project failed")
|
log.Error().Err(err).Msg("create scaffold project failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -6,37 +6,25 @@ import (
|
|||||||
|
|
||||||
func TestGenDemoExamples(t *testing.T) {
|
func TestGenDemoExamples(t *testing.T) {
|
||||||
dir := "../../../examples/demo-with-go-plugin"
|
dir := "../../../examples/demo-with-go-plugin"
|
||||||
err := CreateScaffold(dir, Go, false, true)
|
err := CreateScaffold(dir, Go, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = "../../../examples/demo-with-py-plugin"
|
dir = "../../../examples/demo-with-py-plugin"
|
||||||
err = CreateScaffold(dir, Py, false, true)
|
err = CreateScaffold(dir, Py, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = "../../../examples/demo-without-plugin"
|
dir = "../../../examples/demo-without-plugin"
|
||||||
err = CreateScaffold(dir, Ignore, false, true)
|
err = CreateScaffold(dir, Ignore, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = "../../../examples/empty-demo-without-plugin"
|
dir = "../../../examples/empty-demo-without-plugin"
|
||||||
err = CreateScaffold(dir, Ignore, true, true)
|
err = CreateScaffold(dir, Empty, true)
|
||||||
if err != nil {
|
|
||||||
t.Fatal()
|
|
||||||
}
|
|
||||||
|
|
||||||
dir = "../../../examples/empty-demo-with-py-plugin"
|
|
||||||
err = CreateScaffold(dir, Py, true, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal()
|
|
||||||
}
|
|
||||||
|
|
||||||
dir = "../../../examples/empty-demo-with-go-plugin"
|
|
||||||
err = CreateScaffold(dir, Go, true, true)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
type PluginType string
|
type PluginType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Empty PluginType = "empty"
|
||||||
Ignore PluginType = "ignore"
|
Ignore PluginType = "ignore"
|
||||||
Py PluginType = "py"
|
Py PluginType = "py"
|
||||||
Go PluginType = "go"
|
Go PluginType = "go"
|
||||||
@@ -51,7 +52,7 @@ func CopyFile(templateFile, targetFile string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateScaffold(projectName string, pluginType PluginType, empty bool, force bool) error {
|
func CreateScaffold(projectName string, pluginType PluginType, force bool) error {
|
||||||
// report event
|
// report event
|
||||||
sdk.SendEvent(sdk.EventTracking{
|
sdk.SendEvent(sdk.EventTracking{
|
||||||
Category: "Scaffold",
|
Category: "Scaffold",
|
||||||
@@ -128,13 +129,14 @@ func CreateScaffold(projectName string, pluginType PluginType, empty bool, force
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create project testcases
|
// create project testcases
|
||||||
if empty {
|
if pluginType == Empty {
|
||||||
// create empty project
|
// create empty project
|
||||||
err := CopyFile("templates/testcases/demo_empty_request.json",
|
err := CopyFile("templates/testcases/demo_empty_request.json",
|
||||||
filepath.Join(projectName, "testcases", "requests.json"))
|
filepath.Join(projectName, "testcases", "requests.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
} else if pluginType == Ignore {
|
} else if pluginType == Ignore {
|
||||||
// create project without funplugin
|
// create project without funplugin
|
||||||
err := CopyFile("templates/testcases/demo_without_funplugin.json",
|
err := CopyFile("templates/testcases/demo_without_funplugin.json",
|
||||||
@@ -142,34 +144,32 @@ func CreateScaffold(projectName string, pluginType PluginType, empty bool, force
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// create project with funplugin
|
|
||||||
err = CopyFile("templates/testcases/demo_with_funplugin.json",
|
|
||||||
filepath.Join(projectName, "testcases", "demo.json"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = CopyFile("templates/testcases/demo_requests.json",
|
|
||||||
filepath.Join(projectName, "testcases", "requests.json"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = CopyFile("templates/testcases/demo_requests.yml",
|
|
||||||
filepath.Join(projectName, "testcases", "requests.yml"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = CopyFile("templates/testcases/demo_ref_testcase.yml",
|
|
||||||
filepath.Join(projectName, "testcases", "ref_testcase.yml"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pluginType == Ignore {
|
|
||||||
log.Info().Msg("skip creating function plugin")
|
log.Info().Msg("skip creating function plugin")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create project with funplugin
|
||||||
|
err = CopyFile("templates/testcases/demo_with_funplugin.json",
|
||||||
|
filepath.Join(projectName, "testcases", "demo.json"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = CopyFile("templates/testcases/demo_requests.json",
|
||||||
|
filepath.Join(projectName, "testcases", "requests.json"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = CopyFile("templates/testcases/demo_requests.yml",
|
||||||
|
filepath.Join(projectName, "testcases", "requests.yml"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = CopyFile("templates/testcases/demo_ref_testcase.yml",
|
||||||
|
filepath.Join(projectName, "testcases", "ref_testcase.yml"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// create debugtalk function plugin
|
// create debugtalk function plugin
|
||||||
switch pluginType {
|
switch pluginType {
|
||||||
case Py:
|
case Py:
|
||||||
|
|||||||
Reference in New Issue
Block a user