Merge pull request #1317 from xucong053/add-empty-project

feat: support create empty project with hrp startproject
This commit is contained in:
debugtalk
2022-05-27 11:56:18 +08:00
committed by GitHub
27 changed files with 240 additions and 175 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 27-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 27-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 27-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 27-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 27-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 27-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 27-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 27-May-2022

View File

@@ -1,6 +1,6 @@
{
"project_name": "demo-with-go-plugin",
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-go-plugin",
"create_time": "2022-05-25T11:14:42.750876+08:00",
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin",
"create_time": "2022-05-27T11:34:23.903959+08:00",
"hrp_version": "v4.1.0-beta"
}

View File

@@ -26,8 +26,8 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "application/x-www-form-urlencoded"
data: "foo1=$foo1&foo2=$foo3"
body: "foo1=$foo1&foo2=$foo3"
validate:
- eq: ["status_code", 200]
- eq: ["body.form.foo1", "bar1"]
- eq: ["body.form.foo2", "bar21"]
- eq: ["body.form.foo2", "bar21"]

View File

@@ -38,28 +38,28 @@
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.args.foo1",
"debugtalk"
]
"check": "body.args.foo1",
"assert": "equal",
"expect": "debugtalk",
"msg": "check body.args.foo1"
},
{
"eq": [
"body.args.sum_v",
"3"
]
"check": "body.args.sum_v",
"assert": "equal",
"expect": "3",
"msg": "check body.args.sum_v"
},
{
"eq": [
"body.args.foo2",
"bar21"
]
"check": "body.args.foo2",
"assert": "equal",
"expect": "bar21",
"msg": "check body.args.foo2"
}
]
},
@@ -76,20 +76,20 @@
"User-Agent": "funplugin/${get_version()}",
"Content-Type": "text/plain"
},
"data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
"body": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.data",
"This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."
]
"check": "body.data",
"assert": "equal",
"expect": "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32.",
"msg": "check body.data"
}
]
},
@@ -105,32 +105,32 @@
"User-Agent": "funplugin/${get_version()}",
"Content-Type": "application/x-www-form-urlencoded"
},
"data": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
"body": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.form.foo1",
"$expect_foo1"
]
"check": "body.form.foo1",
"assert": "equal",
"expect": "$expect_foo1",
"msg": "check body.form.foo1"
},
{
"eq": [
"body.form.foo2",
"bar23"
]
"check": "body.form.foo2",
"assert": "equal",
"expect": "bar23",
"msg": "check body.form.foo2"
},
{
"eq": [
"body.form.foo3",
"bar21"
]
"check": "body.form.foo3",
"assert": "equal",
"expect": "bar21",
"msg": "check body.form.foo3"
}
]
}

View File

@@ -42,7 +42,7 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "text/plain"
data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
validate:
- eq: ["status_code", 200]
- eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."]
@@ -56,7 +56,7 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "application/x-www-form-urlencoded"
data: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
body: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
validate:
- eq: ["status_code", 200]
- eq: ["body.form.foo1", "$expect_foo1"]

View File

@@ -1,6 +1,6 @@
{
"project_name": "demo-with-py-plugin",
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-py-plugin",
"create_time": "2022-05-25T11:14:52.333942+08:00",
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin",
"create_time": "2022-05-27T11:34:31.852589+08:00",
"hrp_version": "v4.1.0-beta"
}

View File

@@ -26,8 +26,8 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "application/x-www-form-urlencoded"
data: "foo1=$foo1&foo2=$foo3"
body: "foo1=$foo1&foo2=$foo3"
validate:
- eq: ["status_code", 200]
- eq: ["body.form.foo1", "bar1"]
- eq: ["body.form.foo2", "bar21"]
- eq: ["body.form.foo2", "bar21"]

View File

@@ -38,28 +38,28 @@
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.args.foo1",
"debugtalk"
]
"check": "body.args.foo1",
"assert": "equal",
"expect": "debugtalk",
"msg": "check body.args.foo1"
},
{
"eq": [
"body.args.sum_v",
"3"
]
"check": "body.args.sum_v",
"assert": "equal",
"expect": "3",
"msg": "check body.args.sum_v"
},
{
"eq": [
"body.args.foo2",
"bar21"
]
"check": "body.args.foo2",
"assert": "equal",
"expect": "bar21",
"msg": "check body.args.foo2"
}
]
},
@@ -76,20 +76,20 @@
"User-Agent": "funplugin/${get_version()}",
"Content-Type": "text/plain"
},
"data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
"body": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.data",
"This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."
]
"check": "body.data",
"assert": "equal",
"expect": "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32.",
"msg": "check body.data"
}
]
},
@@ -105,32 +105,32 @@
"User-Agent": "funplugin/${get_version()}",
"Content-Type": "application/x-www-form-urlencoded"
},
"data": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
"body": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.form.foo1",
"$expect_foo1"
]
"check": "body.form.foo1",
"assert": "equal",
"expect": "$expect_foo1",
"msg": "check body.form.foo1"
},
{
"eq": [
"body.form.foo2",
"bar23"
]
"check": "body.form.foo2",
"assert": "equal",
"expect": "bar23",
"msg": "check body.form.foo2"
},
{
"eq": [
"body.form.foo3",
"bar21"
]
"check": "body.form.foo3",
"assert": "equal",
"expect": "bar21",
"msg": "check body.form.foo3"
}
]
}

View File

@@ -42,7 +42,7 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "text/plain"
data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
validate:
- eq: ["status_code", 200]
- eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."]
@@ -56,7 +56,7 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "application/x-www-form-urlencoded"
data: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
body: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
validate:
- eq: ["status_code", 200]
- eq: ["body.form.foo1", "$expect_foo1"]

View File

@@ -1,6 +1,6 @@
{
"project_name": "demo-without-plugin",
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-without-plugin",
"create_time": "2022-05-25T11:14:53.862348+08:00",
"project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin",
"create_time": "2022-05-27T11:34:32.548637+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
@@ -43,6 +45,7 @@ var scaffoldCmd = &cobra.Command{
}
var (
empty bool
ignorePlugin bool
genPythonPlugin bool
genGoPlugin bool
@@ -55,4 +58,5 @@ func init() {
scaffoldCmd.Flags().BoolVar(&genPythonPlugin, "py", true, "generate hashicorp python plugin")
scaffoldCmd.Flags().BoolVar(&genGoPlugin, "go", false, "generate hashicorp go plugin")
scaffoldCmd.Flags().BoolVar(&ignorePlugin, "ignore-plugin", false, "ignore function plugin")
scaffoldCmd.Flags().BoolVar(&empty, "empty", false, "generate empty project")
}

View File

@@ -22,4 +22,10 @@ func TestGenDemoExamples(t *testing.T) {
if err != nil {
t.Fatal()
}
dir = "../../../examples/empty-demo-without-plugin"
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"
@@ -127,8 +128,17 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
return err
}
// create demo testcases
if pluginType == Ignore {
// create project testcases
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",
filepath.Join(projectName, "testcases", "requests.json"))
if err != nil {
@@ -138,6 +148,7 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
return nil
}
// create project with funplugin
err = CopyFile("templates/testcases/demo_with_funplugin.json",
filepath.Join(projectName, "testcases", "demo.json"))
if err != nil {

View File

@@ -0,0 +1,25 @@
{
"config": {
"name": "request methods testcase: empty testcase",
"variables": null,
"verify": false
},
"teststeps": [
{
"name": "",
"variables": null,
"request": {
"method": "GET",
"url": "https://"
},
"validate": [
{
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
}
]
}
]
}

View File

@@ -0,0 +1,13 @@
config:
name: "request methods testcase: empty testcase"
variables:
verify: False
teststeps:
- name:
variables:
request:
method: GET
url: "https://"
validate:
- eq: ["status_code", 200]

View File

@@ -8,16 +8,14 @@
"app_version": "2.8.6"
},
"base_url": "https://postman-echo.com",
"herader": [
{
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "postman-echo.com",
"User-Agent": "PostmanRuntime/7.28.4"
}
],
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Host": "postman-echo.com",
"User-Agent": "PostmanRuntime/7.28.4"
},
"verify": false,
"export": [
"session_token"
@@ -48,16 +46,16 @@
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.headers.postman-token",
"ea19464c-ddd4-4724-abe9-5e2b254c2723"
]
"check": "body.headers.postman-token",
"assert": "equal",
"expect": "ea19464c-ddd4-4724-abe9-5e2b254c2723",
"msg": "check body.headers.postman-token"
}
]
},

View File

@@ -26,8 +26,8 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "application/x-www-form-urlencoded"
data: "foo1=$foo1&foo2=$foo3"
body: "foo1=$foo1&foo2=$foo3"
validate:
- eq: ["status_code", 200]
- eq: ["body.form.foo1", "bar1"]
- eq: ["body.form.foo2", "bar21"]
- eq: ["body.form.foo2", "bar21"]

View File

@@ -38,28 +38,28 @@
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.args.foo1",
"debugtalk"
]
"check": "body.args.foo1",
"assert": "equal",
"expect": "debugtalk",
"msg": "check body.args.foo1"
},
{
"eq": [
"body.args.sum_v",
"3"
]
"check": "body.args.sum_v",
"assert": "equal",
"expect": "3",
"msg": "check body.args.sum_v"
},
{
"eq": [
"body.args.foo2",
"bar21"
]
"check": "body.args.foo2",
"assert": "equal",
"expect": "bar21",
"msg": "check body.args.foo2"
}
]
},
@@ -76,20 +76,20 @@
"User-Agent": "funplugin/${get_version()}",
"Content-Type": "text/plain"
},
"data": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
"body": "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.data",
"This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."
]
"check": "body.data",
"assert": "equal",
"expect": "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32.",
"msg": "check body.data"
}
]
},
@@ -105,32 +105,32 @@
"User-Agent": "funplugin/${get_version()}",
"Content-Type": "application/x-www-form-urlencoded"
},
"data": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
"body": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
},
"validate": [
{
"eq": [
"status_code",
200
]
"check": "status_code",
"assert": "equal",
"expect": 200,
"msg": "check status_code"
},
{
"eq": [
"body.form.foo1",
"$expect_foo1"
]
"check": "body.form.foo1",
"assert": "equal",
"expect": "$expect_foo1",
"msg": "check body.form.foo1"
},
{
"eq": [
"body.form.foo2",
"bar23"
]
"check": "body.form.foo2",
"assert": "equal",
"expect": "bar23",
"msg": "check body.form.foo2"
},
{
"eq": [
"body.form.foo3",
"bar21"
]
"check": "body.form.foo3",
"assert": "equal",
"expect": "bar21",
"msg": "check body.form.foo3"
}
]
}

View File

@@ -42,7 +42,7 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "text/plain"
data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
validate:
- eq: ["status_code", 200]
- eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."]
@@ -56,7 +56,7 @@ teststeps:
headers:
User-Agent: funplugin/${get_version()}
Content-Type: "application/x-www-form-urlencoded"
data: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
body: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
validate:
- eq: ["status_code", 200]
- eq: ["body.form.foo1", "$expect_foo1"]

View File

@@ -17,6 +17,7 @@ const (
goPluginFile = "debugtalk.so" // built from go plugin
hashicorpGoPluginFile = "debugtalk.bin" // built from hashicorp go plugin
hashicorpPyPluginFile = "debugtalk.py" // used for hashicorp python plugin
projectInfoFile = "proj.json" // used for ensuring root project
)
func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir string, err error) {
@@ -118,9 +119,15 @@ func GetProjectRootDirPath(path string) (rootDir string, err error) {
rootDir = filepath.Dir(pluginPath)
return
}
// fix: no debugtalk file in project but having proj.json created by startpeoject
projPath, err := locateFile(path, projectInfoFile)
if err == nil {
rootDir = filepath.Dir(projPath)
return
}
// failed to locate project root dir
// maybe project plugin debugtalk.xx is not exist
// maybe project plugin debugtalk.xx and proj.json are not exist
// use current dir instead
return os.Getwd()
}