diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index 74a6c8b2..c9499319 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -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 diff --git a/docs/cmd/hrp_boom.md b/docs/cmd/hrp_boom.md index f6eb3a55..429a0ed3 100644 --- a/docs/cmd/hrp_boom.md +++ b/docs/cmd/hrp_boom.md @@ -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 diff --git a/docs/cmd/hrp_convert.md b/docs/cmd/hrp_convert.md index c3b1b5cc..3083456c 100644 --- a/docs/cmd/hrp_convert.md +++ b/docs/cmd/hrp_convert.md @@ -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 diff --git a/docs/cmd/hrp_har2case.md b/docs/cmd/hrp_har2case.md index a37bbf1e..592c5281 100644 --- a/docs/cmd/hrp_har2case.md +++ b/docs/cmd/hrp_har2case.md @@ -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 diff --git a/docs/cmd/hrp_pytest.md b/docs/cmd/hrp_pytest.md index 30682a20..711c8bac 100644 --- a/docs/cmd/hrp_pytest.md +++ b/docs/cmd/hrp_pytest.md @@ -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 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index 46725b8a..63da347e 100644 --- a/docs/cmd/hrp_run.md +++ b/docs/cmd/hrp_run.md @@ -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 diff --git a/docs/cmd/hrp_startproject.md b/docs/cmd/hrp_startproject.md index eb0b6bb9..e55c5429 100644 --- a/docs/cmd/hrp_startproject.md +++ b/docs/cmd/hrp_startproject.md @@ -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 diff --git a/docs/cmd/hrp_wiki.md b/docs/cmd/hrp_wiki.md index 1219555f..2eecbdd0 100644 --- a/docs/cmd/hrp_wiki.md +++ b/docs/cmd/hrp_wiki.md @@ -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 diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json index 4dea84bc..2b2fcb6b 100644 --- a/examples/demo-with-go-plugin/proj.json +++ b/examples/demo-with-go-plugin/proj.json @@ -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" } \ No newline at end of file diff --git a/examples/demo-with-go-plugin/testcases/ref_testcase.yml b/examples/demo-with-go-plugin/testcases/ref_testcase.yml index 6cf32323..0816481c 100644 --- a/examples/demo-with-go-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -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"] \ No newline at end of file diff --git a/examples/demo-with-go-plugin/testcases/requests.json b/examples/demo-with-go-plugin/testcases/requests.json index 9b4214d7..162632b4 100644 --- a/examples/demo-with-go-plugin/testcases/requests.json +++ b/examples/demo-with-go-plugin/testcases/requests.json @@ -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" } ] } diff --git a/examples/demo-with-go-plugin/testcases/requests.yml b/examples/demo-with-go-plugin/testcases/requests.yml index bc9aa108..034dbefb 100644 --- a/examples/demo-with-go-plugin/testcases/requests.yml +++ b/examples/demo-with-go-plugin/testcases/requests.yml @@ -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"] diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index cca69211..555bccd7 100644 --- a/examples/demo-with-py-plugin/proj.json +++ b/examples/demo-with-py-plugin/proj.json @@ -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" } \ No newline at end of file diff --git a/examples/demo-with-py-plugin/testcases/ref_testcase.yml b/examples/demo-with-py-plugin/testcases/ref_testcase.yml index 6cf32323..0816481c 100644 --- a/examples/demo-with-py-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-py-plugin/testcases/ref_testcase.yml @@ -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"] \ No newline at end of file diff --git a/examples/demo-with-py-plugin/testcases/requests.json b/examples/demo-with-py-plugin/testcases/requests.json index 9b4214d7..162632b4 100644 --- a/examples/demo-with-py-plugin/testcases/requests.json +++ b/examples/demo-with-py-plugin/testcases/requests.json @@ -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" } ] } diff --git a/examples/demo-with-py-plugin/testcases/requests.yml b/examples/demo-with-py-plugin/testcases/requests.yml index bc9aa108..034dbefb 100644 --- a/examples/demo-with-py-plugin/testcases/requests.yml +++ b/examples/demo-with-py-plugin/testcases/requests.yml @@ -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"] diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index 3fabec85..72c78cbf 100644 --- a/examples/demo-without-plugin/proj.json +++ b/examples/demo-without-plugin/proj.json @@ -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" } \ No newline at end of file diff --git a/hrp/cmd/scaffold.go b/hrp/cmd/scaffold.go index 93a8e4b8..c51281ed 100644 --- a/hrp/cmd/scaffold.go +++ b/hrp/cmd/scaffold.go @@ -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") } diff --git a/hrp/internal/scaffold/examples_test.go b/hrp/internal/scaffold/examples_test.go index 3ec85cb5..3bde77b0 100644 --- a/hrp/internal/scaffold/examples_test.go +++ b/hrp/internal/scaffold/examples_test.go @@ -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() + } } diff --git a/hrp/internal/scaffold/main.go b/hrp/internal/scaffold/main.go index 3392d960..0941838d 100644 --- a/hrp/internal/scaffold/main.go +++ b/hrp/internal/scaffold/main.go @@ -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 { diff --git a/hrp/internal/scaffold/templates/testcases/demo_empty_request.json b/hrp/internal/scaffold/templates/testcases/demo_empty_request.json new file mode 100644 index 00000000..fc76e4aa --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_empty_request.json @@ -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" + } + ] + } + ] +} \ No newline at end of file diff --git a/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml b/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml new file mode 100644 index 00000000..38e7c4a8 --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml @@ -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] diff --git a/hrp/internal/scaffold/templates/testcases/demo_ref_api.json b/hrp/internal/scaffold/templates/testcases/demo_ref_api.json index 8e69392f..7bc33c5e 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_api.json +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_api.json @@ -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" } ] }, diff --git a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml index 6cf32323..0816481c 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml @@ -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"] \ No newline at end of file diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.json b/hrp/internal/scaffold/templates/testcases/demo_requests.json index 9b4214d7..162632b4 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.json +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.json @@ -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" } ] } diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.yml b/hrp/internal/scaffold/templates/testcases/demo_requests.yml index bc9aa108..034dbefb 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.yml @@ -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"] diff --git a/hrp/plugin.go b/hrp/plugin.go index 67a86cfe..f9465a90 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -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() }