fix: modify logic of generating empty project

This commit is contained in:
xucong053
2022-05-26 22:06:02 +08:00
parent ef73243e04
commit 434decaa78
14 changed files with 48 additions and 57 deletions

View File

@@ -37,4 +37,4 @@ Copyright 2017 debugtalk
* [hrp startproject](hrp_startproject.md) - create a scaffold project
* [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

View File

@@ -42,4 +42,4 @@ hrp boom [flags]
* [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

View File

@@ -22,4 +22,4 @@ hrp convert $path... [flags]
* [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

View File

@@ -16,7 +16,7 @@ hrp har2case $har_path... [flags]
-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 true)
-j, --to-json convert to JSON format (default)
-y, --to-yaml convert to YAML format
```
@@ -24,4 +24,4 @@ hrp har2case $har_path... [flags]
* [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

View File

@@ -16,4 +16,4 @@ hrp pytest $path ... [flags]
* [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

View File

@@ -35,4 +35,4 @@ hrp run $path... [flags]
* [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

View File

@@ -9,6 +9,7 @@ hrp startproject $project_name [flags]
### Options
```
--empty generate empty project
-f, --force force to overwrite existing project
--go generate hashicorp go plugin
-h, --help help for startproject
@@ -20,4 +21,4 @@ hrp startproject $project_name [flags]
* [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

View File

@@ -16,4 +16,4 @@ hrp wiki [flags]
* [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

View File

@@ -1,6 +1,6 @@
{
"project_name": "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"
}

View File

@@ -1,6 +1,6 @@
{
"project_name": "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"
}

View File

@@ -1,6 +1,6 @@
{
"project_name": "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"
}

View File

@@ -24,7 +24,9 @@ var scaffoldCmd = &cobra.Command{
}
var pluginType scaffold.PluginType
if ignorePlugin {
if empty {
pluginType = scaffold.Empty
} else if ignorePlugin {
pluginType = scaffold.Ignore
} else if genGoPlugin {
pluginType = scaffold.Go
@@ -32,7 +34,7 @@ var scaffoldCmd = &cobra.Command{
pluginType = scaffold.Py // default
}
err := scaffold.CreateScaffold(args[0], pluginType, empty, force)
err := scaffold.CreateScaffold(args[0], pluginType, force)
if err != nil {
log.Error().Err(err).Msg("create scaffold project failed")
os.Exit(1)

View File

@@ -6,37 +6,25 @@ import (
func TestGenDemoExamples(t *testing.T) {
dir := "../../../examples/demo-with-go-plugin"
err := CreateScaffold(dir, Go, false, true)
err := CreateScaffold(dir, Go, true)
if err != nil {
t.Fatal()
}
dir = "../../../examples/demo-with-py-plugin"
err = CreateScaffold(dir, Py, false, true)
err = CreateScaffold(dir, Py, true)
if err != nil {
t.Fatal()
}
dir = "../../../examples/demo-without-plugin"
err = CreateScaffold(dir, Ignore, false, true)
err = CreateScaffold(dir, Ignore, true)
if err != nil {
t.Fatal()
}
dir = "../../../examples/empty-demo-without-plugin"
err = CreateScaffold(dir, Ignore, true, 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)
err = CreateScaffold(dir, Empty, true)
if err != nil {
t.Fatal()
}

View File

@@ -20,6 +20,7 @@ import (
type PluginType string
const (
Empty PluginType = "empty"
Ignore PluginType = "ignore"
Py PluginType = "py"
Go PluginType = "go"
@@ -51,7 +52,7 @@ func CopyFile(templateFile, targetFile string) error {
return nil
}
func CreateScaffold(projectName string, pluginType PluginType, empty bool, force bool) error {
func CreateScaffold(projectName string, pluginType PluginType, force bool) error {
// report event
sdk.SendEvent(sdk.EventTracking{
Category: "Scaffold",
@@ -128,13 +129,14 @@ func CreateScaffold(projectName string, pluginType PluginType, empty bool, force
}
// create project testcases
if empty {
if pluginType == Empty {
// create empty project
err := CopyFile("templates/testcases/demo_empty_request.json",
filepath.Join(projectName, "testcases", "requests.json"))
if err != nil {
return err
}
return nil
} else if pluginType == Ignore {
// create project without funplugin
err := CopyFile("templates/testcases/demo_without_funplugin.json",
@@ -142,34 +144,32 @@ func CreateScaffold(projectName string, pluginType PluginType, empty bool, force
if err != nil {
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")
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
switch pluginType {
case Py: