From c59c859e737a39ec1e3b0a396e628d7d797e4718 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Mon, 23 May 2022 21:50:45 +0800 Subject: [PATCH 1/5] feat: create empty project by using hrp startproject #1280 --- examples/demo-with-go-plugin/proj.json | 6 -- .../testcases/ref_testcase.yml | 15 +++- .../testcases/requests.json | 80 +++++++++---------- .../testcases/requests.yml | 50 +++++++++--- examples/demo-with-py-plugin/proj.json | 6 -- .../testcases/ref_testcase.yml | 15 +++- .../testcases/requests.json | 80 +++++++++---------- .../testcases/requests.yml | 50 +++++++++--- examples/demo-without-plugin/proj.json | 6 -- hrp/cmd/scaffold.go | 4 +- hrp/internal/scaffold/examples_test.go | 24 +++++- hrp/internal/scaffold/main.go | 61 ++++++++------ .../testcases/demo_empty_request.json | 25 ++++++ .../testcases/demo_empty_request.yml | 16 ++++ .../templates/testcases/demo_ref_testcase.yml | 15 +++- .../templates/testcases/demo_requests.json | 80 +++++++++---------- .../templates/testcases/demo_requests.yml | 50 +++++++++--- 17 files changed, 377 insertions(+), 206 deletions(-) delete mode 100644 examples/demo-with-go-plugin/proj.json delete mode 100644 examples/demo-with-py-plugin/proj.json delete mode 100644 examples/demo-without-plugin/proj.json create mode 100644 hrp/internal/scaffold/templates/testcases/demo_empty_request.json create mode 100644 hrp/internal/scaffold/templates/testcases/demo_empty_request.yml diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json deleted file mode 100644 index 4dea84bc..00000000 --- a/examples/demo-with-go-plugin/proj.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "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", - "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..b904706f 100644 --- a/examples/demo-with-go-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -28,6 +28,15 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" data: "foo1=$foo1&foo2=$foo3" validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] - - eq: ["body.form.foo2", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.form.foo1 + assert: equal + expect: bar1 + msg: check body.form.foo1 + - check: body.form.foo2 + assert: equal + expect: bar21 + msg: check body.form.foo2 \ 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..24d3d38d 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" } ] }, @@ -80,16 +80,16 @@ }, "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" } ] }, @@ -109,28 +109,28 @@ }, "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..a713830b 100644 --- a/examples/demo-with-go-plugin/testcases/requests.yml +++ b/examples/demo-with-go-plugin/testcases/requests.yml @@ -27,10 +27,22 @@ teststeps: extract: foo3: "body.args.foo2" validate: - - eq: ["status_code", 200] - - eq: ["body.args.foo1", "debugtalk"] - - eq: ["body.args.sum_v", "3"] - - eq: ["body.args.foo2", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.args.foo1 + assert: equal + expect: debugtalk + msg: check body.args.foo1 + - check: body.args.sum_v + assert: equal + expect: "3" + msg: check body.args.sum_v + - check: body.args.foo2 + assert: equal + expect: bar21 + msg: check body.args.foo2 - name: post raw text variables: @@ -44,8 +56,14 @@ teststeps: Content-Type: "text/plain" data: "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."] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - 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 - name: post form data variables: @@ -58,7 +76,19 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "$expect_foo1"] - - eq: ["body.form.foo2", "bar23"] - - eq: ["body.form.foo3", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.form.foo1 + assert: equal + expect: $expect_foo1 + msg: check body.form.foo1 + - check: body.form.foo2 + assert: equal + expect: bar23 + msg: check body.form.foo2 + - check: body.form.foo3 + assert: equal + expect: bar21 + msg: check body.form.foo3 diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json deleted file mode 100644 index cca69211..00000000 --- a/examples/demo-with-py-plugin/proj.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "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", - "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..b904706f 100644 --- a/examples/demo-with-py-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-py-plugin/testcases/ref_testcase.yml @@ -28,6 +28,15 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" data: "foo1=$foo1&foo2=$foo3" validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] - - eq: ["body.form.foo2", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.form.foo1 + assert: equal + expect: bar1 + msg: check body.form.foo1 + - check: body.form.foo2 + assert: equal + expect: bar21 + msg: check body.form.foo2 \ 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..24d3d38d 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" } ] }, @@ -80,16 +80,16 @@ }, "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" } ] }, @@ -109,28 +109,28 @@ }, "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..a713830b 100644 --- a/examples/demo-with-py-plugin/testcases/requests.yml +++ b/examples/demo-with-py-plugin/testcases/requests.yml @@ -27,10 +27,22 @@ teststeps: extract: foo3: "body.args.foo2" validate: - - eq: ["status_code", 200] - - eq: ["body.args.foo1", "debugtalk"] - - eq: ["body.args.sum_v", "3"] - - eq: ["body.args.foo2", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.args.foo1 + assert: equal + expect: debugtalk + msg: check body.args.foo1 + - check: body.args.sum_v + assert: equal + expect: "3" + msg: check body.args.sum_v + - check: body.args.foo2 + assert: equal + expect: bar21 + msg: check body.args.foo2 - name: post raw text variables: @@ -44,8 +56,14 @@ teststeps: Content-Type: "text/plain" data: "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."] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - 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 - name: post form data variables: @@ -58,7 +76,19 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "$expect_foo1"] - - eq: ["body.form.foo2", "bar23"] - - eq: ["body.form.foo3", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.form.foo1 + assert: equal + expect: $expect_foo1 + msg: check body.form.foo1 + - check: body.form.foo2 + assert: equal + expect: bar23 + msg: check body.form.foo2 + - check: body.form.foo3 + assert: equal + expect: bar21 + msg: check body.form.foo3 diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json deleted file mode 100644 index 3fabec85..00000000 --- a/examples/demo-without-plugin/proj.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "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", - "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..42b8accb 100644 --- a/hrp/cmd/scaffold.go +++ b/hrp/cmd/scaffold.go @@ -32,7 +32,7 @@ var scaffoldCmd = &cobra.Command{ pluginType = scaffold.Py // default } - err := scaffold.CreateScaffold(args[0], pluginType, force) + err := scaffold.CreateScaffold(args[0], pluginType, empty, force) if err != nil { log.Error().Err(err).Msg("create scaffold project failed") os.Exit(1) @@ -43,6 +43,7 @@ var scaffoldCmd = &cobra.Command{ } var ( + empty bool ignorePlugin bool genPythonPlugin bool genGoPlugin bool @@ -55,4 +56,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..dc992a99 100644 --- a/hrp/internal/scaffold/examples_test.go +++ b/hrp/internal/scaffold/examples_test.go @@ -6,19 +6,37 @@ import ( func TestGenDemoExamples(t *testing.T) { dir := "../../../examples/demo-with-go-plugin" - err := CreateScaffold(dir, Go, true) + err := CreateScaffold(dir, Go, false, true) if err != nil { t.Fatal() } dir = "../../../examples/demo-with-py-plugin" - err = CreateScaffold(dir, Py, true) + err = CreateScaffold(dir, Py, false, true) if err != nil { t.Fatal() } dir = "../../../examples/demo-without-plugin" - err = CreateScaffold(dir, Ignore, true) + err = CreateScaffold(dir, Ignore, false, 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) if err != nil { t.Fatal() } diff --git a/hrp/internal/scaffold/main.go b/hrp/internal/scaffold/main.go index 3392d960..61ea346d 100644 --- a/hrp/internal/scaffold/main.go +++ b/hrp/internal/scaffold/main.go @@ -51,7 +51,7 @@ func CopyFile(templateFile, targetFile string) error { return nil } -func CreateScaffold(projectName string, pluginType PluginType, force bool) error { +func CreateScaffold(projectName string, pluginType PluginType, empty bool, force bool) error { // report event sdk.SendEvent(sdk.EventTracking{ Category: "Scaffold", @@ -127,38 +127,49 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error return err } - // create demo testcases - if pluginType == Ignore { + // create project testcases + if empty { + // create empty project + err := CopyFile("templates/testcases/demo_empty_request.json", + filepath.Join(projectName, "testcases", "requests.json")) + if err != nil { + return err + } + } 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 { 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 } - - 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: 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..21586762 --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml @@ -0,0 +1,16 @@ +config: + name: "request methods testcase: empty testcase" + variables: + verify: False + +teststeps: + - name: + variables: + request: + method: GET + url: "https://" + validate: + - check: status_code + assert: equal + expect: 200 + msg: check status_code diff --git a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml index 6cf32323..b904706f 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml @@ -28,6 +28,15 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" data: "foo1=$foo1&foo2=$foo3" validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "bar1"] - - eq: ["body.form.foo2", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.form.foo1 + assert: equal + expect: bar1 + msg: check body.form.foo1 + - check: body.form.foo2 + assert: equal + expect: bar21 + msg: check body.form.foo2 \ 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..24d3d38d 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" } ] }, @@ -80,16 +80,16 @@ }, "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" } ] }, @@ -109,28 +109,28 @@ }, "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..a713830b 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.yml @@ -27,10 +27,22 @@ teststeps: extract: foo3: "body.args.foo2" validate: - - eq: ["status_code", 200] - - eq: ["body.args.foo1", "debugtalk"] - - eq: ["body.args.sum_v", "3"] - - eq: ["body.args.foo2", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.args.foo1 + assert: equal + expect: debugtalk + msg: check body.args.foo1 + - check: body.args.sum_v + assert: equal + expect: "3" + msg: check body.args.sum_v + - check: body.args.foo2 + assert: equal + expect: bar21 + msg: check body.args.foo2 - name: post raw text variables: @@ -44,8 +56,14 @@ teststeps: Content-Type: "text/plain" data: "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."] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - 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 - name: post form data variables: @@ -58,7 +76,19 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" data: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: - - eq: ["status_code", 200] - - eq: ["body.form.foo1", "$expect_foo1"] - - eq: ["body.form.foo2", "bar23"] - - eq: ["body.form.foo3", "bar21"] + - check: status_code + assert: equal + expect: 200 + msg: check status_code + - check: body.form.foo1 + assert: equal + expect: $expect_foo1 + msg: check body.form.foo1 + - check: body.form.foo2 + assert: equal + expect: bar23 + msg: check body.form.foo2 + - check: body.form.foo3 + assert: equal + expect: bar21 + msg: check body.form.foo3 From f39a82755e45d15e2d4a104df6f6984bc7cf85d5 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 26 May 2022 17:39:11 +0800 Subject: [PATCH 2/5] fix: failed to locate root dir even if proj.json exist --- hrp/plugin.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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() } From a1f189b3f4fa54bc164be1149d3a3c74178ff3ce Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 26 May 2022 20:11:46 +0800 Subject: [PATCH 3/5] fix: unittest --- examples/demo-with-go-plugin/proj.json | 6 ++++ .../testcases/ref_testcase.yml | 2 +- .../testcases/requests.json | 4 +-- .../testcases/requests.yml | 4 +-- examples/demo-with-py-plugin/proj.json | 6 ++++ .../testcases/ref_testcase.yml | 2 +- .../testcases/requests.json | 4 +-- .../testcases/requests.yml | 4 +-- examples/demo-without-plugin/proj.json | 6 ++++ .../templates/testcases/demo_ref_api.json | 34 +++++++++---------- .../templates/testcases/demo_ref_testcase.yml | 2 +- .../templates/testcases/demo_requests.json | 4 +-- .../templates/testcases/demo_requests.yml | 4 +-- 13 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 examples/demo-with-go-plugin/proj.json create mode 100644 examples/demo-with-py-plugin/proj.json create mode 100644 examples/demo-without-plugin/proj.json diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json new file mode 100644 index 00000000..c845ecfa --- /dev/null +++ b/examples/demo-with-go-plugin/proj.json @@ -0,0 +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", + "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 b904706f..e102b9ec 100644 --- a/examples/demo-with-go-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -26,7 +26,7 @@ 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: - check: status_code assert: equal diff --git a/examples/demo-with-go-plugin/testcases/requests.json b/examples/demo-with-go-plugin/testcases/requests.json index 24d3d38d..162632b4 100644 --- a/examples/demo-with-go-plugin/testcases/requests.json +++ b/examples/demo-with-go-plugin/testcases/requests.json @@ -76,7 +76,7 @@ "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": [ { @@ -105,7 +105,7 @@ "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": [ { diff --git a/examples/demo-with-go-plugin/testcases/requests.yml b/examples/demo-with-go-plugin/testcases/requests.yml index a713830b..988c970f 100644 --- a/examples/demo-with-go-plugin/testcases/requests.yml +++ b/examples/demo-with-go-plugin/testcases/requests.yml @@ -54,7 +54,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: - check: status_code assert: equal @@ -74,7 +74,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: - check: status_code assert: equal diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json new file mode 100644 index 00000000..e950c12c --- /dev/null +++ b/examples/demo-with-py-plugin/proj.json @@ -0,0 +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", + "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 b904706f..e102b9ec 100644 --- a/examples/demo-with-py-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-py-plugin/testcases/ref_testcase.yml @@ -26,7 +26,7 @@ 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: - check: status_code assert: equal diff --git a/examples/demo-with-py-plugin/testcases/requests.json b/examples/demo-with-py-plugin/testcases/requests.json index 24d3d38d..162632b4 100644 --- a/examples/demo-with-py-plugin/testcases/requests.json +++ b/examples/demo-with-py-plugin/testcases/requests.json @@ -76,7 +76,7 @@ "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": [ { @@ -105,7 +105,7 @@ "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": [ { diff --git a/examples/demo-with-py-plugin/testcases/requests.yml b/examples/demo-with-py-plugin/testcases/requests.yml index a713830b..988c970f 100644 --- a/examples/demo-with-py-plugin/testcases/requests.yml +++ b/examples/demo-with-py-plugin/testcases/requests.yml @@ -54,7 +54,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: - check: status_code assert: equal @@ -74,7 +74,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: - check: status_code assert: equal diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json new file mode 100644 index 00000000..80cc140d --- /dev/null +++ b/examples/demo-without-plugin/proj.json @@ -0,0 +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", + "hrp_version": "v4.1.0-beta" +} \ No newline at end of file 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 b904706f..e102b9ec 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml @@ -26,7 +26,7 @@ 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: - check: status_code assert: equal diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.json b/hrp/internal/scaffold/templates/testcases/demo_requests.json index 24d3d38d..162632b4 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.json +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.json @@ -76,7 +76,7 @@ "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": [ { @@ -105,7 +105,7 @@ "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": [ { diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.yml b/hrp/internal/scaffold/templates/testcases/demo_requests.yml index a713830b..988c970f 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.yml @@ -54,7 +54,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: - check: status_code assert: equal @@ -74,7 +74,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: - check: status_code assert: equal From 30bc80e456b79cc3dc59a7b5afbdc8fd1f78c643 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Thu, 26 May 2022 22:06:02 +0800 Subject: [PATCH 4/5] fix: modify logic of generating empty project --- docs/cmd/hrp.md | 2 +- docs/cmd/hrp_boom.md | 2 +- docs/cmd/hrp_convert.md | 2 +- docs/cmd/hrp_har2case.md | 4 +- docs/cmd/hrp_pytest.md | 2 +- docs/cmd/hrp_run.md | 2 +- docs/cmd/hrp_startproject.md | 3 +- docs/cmd/hrp_wiki.md | 2 +- examples/demo-with-go-plugin/proj.json | 2 +- examples/demo-with-py-plugin/proj.json | 2 +- examples/demo-without-plugin/proj.json | 2 +- hrp/cmd/scaffold.go | 6 ++- hrp/internal/scaffold/examples_test.go | 20 ++-------- hrp/internal/scaffold/main.go | 54 +++++++++++++------------- 14 files changed, 48 insertions(+), 57 deletions(-) diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index 74a6c8b2..a1b46ac0 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 26-May-2022 diff --git a/docs/cmd/hrp_boom.md b/docs/cmd/hrp_boom.md index f6eb3a55..78dc8845 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 26-May-2022 diff --git a/docs/cmd/hrp_convert.md b/docs/cmd/hrp_convert.md index c3b1b5cc..9d0bf745 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 26-May-2022 diff --git a/docs/cmd/hrp_har2case.md b/docs/cmd/hrp_har2case.md index a37bbf1e..8ca7631e 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 26-May-2022 diff --git a/docs/cmd/hrp_pytest.md b/docs/cmd/hrp_pytest.md index 30682a20..ebc5a25d 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 26-May-2022 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index 46725b8a..2dd34349 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 26-May-2022 diff --git a/docs/cmd/hrp_startproject.md b/docs/cmd/hrp_startproject.md index eb0b6bb9..00ab67ab 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 26-May-2022 diff --git a/docs/cmd/hrp_wiki.md b/docs/cmd/hrp_wiki.md index 1219555f..932f1133 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 26-May-2022 diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json index c845ecfa..1c051514 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/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" } \ No newline at end of file diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index e950c12c..a1f7d451 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/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" } \ No newline at end of file diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index 80cc140d..92230cbb 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/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" } \ No newline at end of file diff --git a/hrp/cmd/scaffold.go b/hrp/cmd/scaffold.go index 42b8accb..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 @@ -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) diff --git a/hrp/internal/scaffold/examples_test.go b/hrp/internal/scaffold/examples_test.go index dc992a99..3bde77b0 100644 --- a/hrp/internal/scaffold/examples_test.go +++ b/hrp/internal/scaffold/examples_test.go @@ -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() } diff --git a/hrp/internal/scaffold/main.go b/hrp/internal/scaffold/main.go index 61ea346d..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" @@ -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: From 83c554decb62af30b29e956f2167feb596cdfb32 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Fri, 27 May 2022 11:29:41 +0800 Subject: [PATCH 5/5] update templates/testcases --- docs/cmd/hrp.md | 2 +- docs/cmd/hrp_boom.md | 2 +- docs/cmd/hrp_convert.md | 2 +- docs/cmd/hrp_har2case.md | 2 +- docs/cmd/hrp_pytest.md | 2 +- docs/cmd/hrp_run.md | 2 +- docs/cmd/hrp_startproject.md | 2 +- docs/cmd/hrp_wiki.md | 2 +- examples/demo-with-go-plugin/proj.json | 2 +- .../testcases/ref_testcase.yml | 15 ++---- .../testcases/requests.yml | 50 ++++--------------- examples/demo-with-py-plugin/proj.json | 2 +- .../testcases/ref_testcase.yml | 15 ++---- .../testcases/requests.yml | 50 ++++--------------- examples/demo-without-plugin/proj.json | 2 +- .../testcases/demo_empty_request.yml | 5 +- .../templates/testcases/demo_ref_testcase.yml | 15 ++---- .../templates/testcases/demo_requests.yml | 50 ++++--------------- 18 files changed, 51 insertions(+), 171 deletions(-) diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index a1b46ac0..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 26-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 78dc8845..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 26-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 9d0bf745..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 26-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 8ca7631e..592c5281 100644 --- a/docs/cmd/hrp_har2case.md +++ b/docs/cmd/hrp_har2case.md @@ -24,4 +24,4 @@ hrp har2case $har_path... [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 26-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 ebc5a25d..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 26-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 2dd34349..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 26-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 00ab67ab..e55c5429 100644 --- a/docs/cmd/hrp_startproject.md +++ b/docs/cmd/hrp_startproject.md @@ -21,4 +21,4 @@ hrp startproject $project_name [flags] * [hrp](hrp.md) - Next-Generation API Testing Solution. -###### Auto generated by spf13/cobra on 26-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 932f1133..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 26-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 1c051514..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/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin", - "create_time": "2022-05-26T22:08:10.455301+08:00", + "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 e102b9ec..0816481c 100644 --- a/examples/demo-with-go-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -28,15 +28,6 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo3" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.form.foo1 - assert: equal - expect: bar1 - msg: check body.form.foo1 - - check: body.form.foo2 - assert: equal - expect: bar21 - msg: check body.form.foo2 \ No newline at end of file + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo2", "bar21"] \ No newline at end of file diff --git a/examples/demo-with-go-plugin/testcases/requests.yml b/examples/demo-with-go-plugin/testcases/requests.yml index 988c970f..034dbefb 100644 --- a/examples/demo-with-go-plugin/testcases/requests.yml +++ b/examples/demo-with-go-plugin/testcases/requests.yml @@ -27,22 +27,10 @@ teststeps: extract: foo3: "body.args.foo2" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.args.foo1 - assert: equal - expect: debugtalk - msg: check body.args.foo1 - - check: body.args.sum_v - assert: equal - expect: "3" - msg: check body.args.sum_v - - check: body.args.foo2 - assert: equal - expect: bar21 - msg: check body.args.foo2 + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "debugtalk"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "bar21"] - name: post raw text variables: @@ -56,14 +44,8 @@ teststeps: Content-Type: "text/plain" body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - 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 + - eq: ["status_code", 200] + - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] - name: post form data variables: @@ -76,19 +58,7 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.form.foo1 - assert: equal - expect: $expect_foo1 - msg: check body.form.foo1 - - check: body.form.foo2 - assert: equal - expect: bar23 - msg: check body.form.foo2 - - check: body.form.foo3 - assert: equal - expect: bar21 - msg: check body.form.foo3 + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "$expect_foo1"] + - eq: ["body.form.foo2", "bar23"] + - eq: ["body.form.foo3", "bar21"] diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index a1f7d451..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/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin", - "create_time": "2022-05-26T22:08:18.580462+08:00", + "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 e102b9ec..0816481c 100644 --- a/examples/demo-with-py-plugin/testcases/ref_testcase.yml +++ b/examples/demo-with-py-plugin/testcases/ref_testcase.yml @@ -28,15 +28,6 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo3" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.form.foo1 - assert: equal - expect: bar1 - msg: check body.form.foo1 - - check: body.form.foo2 - assert: equal - expect: bar21 - msg: check body.form.foo2 \ No newline at end of file + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo2", "bar21"] \ No newline at end of file diff --git a/examples/demo-with-py-plugin/testcases/requests.yml b/examples/demo-with-py-plugin/testcases/requests.yml index 988c970f..034dbefb 100644 --- a/examples/demo-with-py-plugin/testcases/requests.yml +++ b/examples/demo-with-py-plugin/testcases/requests.yml @@ -27,22 +27,10 @@ teststeps: extract: foo3: "body.args.foo2" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.args.foo1 - assert: equal - expect: debugtalk - msg: check body.args.foo1 - - check: body.args.sum_v - assert: equal - expect: "3" - msg: check body.args.sum_v - - check: body.args.foo2 - assert: equal - expect: bar21 - msg: check body.args.foo2 + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "debugtalk"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "bar21"] - name: post raw text variables: @@ -56,14 +44,8 @@ teststeps: Content-Type: "text/plain" body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - 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 + - eq: ["status_code", 200] + - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] - name: post form data variables: @@ -76,19 +58,7 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.form.foo1 - assert: equal - expect: $expect_foo1 - msg: check body.form.foo1 - - check: body.form.foo2 - assert: equal - expect: bar23 - msg: check body.form.foo2 - - check: body.form.foo3 - assert: equal - expect: bar21 - msg: check body.form.foo3 + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "$expect_foo1"] + - eq: ["body.form.foo2", "bar23"] + - eq: ["body.form.foo3", "bar21"] diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index 92230cbb..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/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin", - "create_time": "2022-05-26T22:08:19.331271+08:00", + "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/internal/scaffold/templates/testcases/demo_empty_request.yml b/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml index 21586762..38e7c4a8 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_empty_request.yml @@ -10,7 +10,4 @@ teststeps: method: GET url: "https://" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code + - eq: ["status_code", 200] diff --git a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml index e102b9ec..0816481c 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml @@ -28,15 +28,6 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo3" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.form.foo1 - assert: equal - expect: bar1 - msg: check body.form.foo1 - - check: body.form.foo2 - assert: equal - expect: bar21 - msg: check body.form.foo2 \ No newline at end of file + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "bar1"] + - eq: ["body.form.foo2", "bar21"] \ No newline at end of file diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.yml b/hrp/internal/scaffold/templates/testcases/demo_requests.yml index 988c970f..034dbefb 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.yml @@ -27,22 +27,10 @@ teststeps: extract: foo3: "body.args.foo2" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.args.foo1 - assert: equal - expect: debugtalk - msg: check body.args.foo1 - - check: body.args.sum_v - assert: equal - expect: "3" - msg: check body.args.sum_v - - check: body.args.foo2 - assert: equal - expect: bar21 - msg: check body.args.foo2 + - eq: ["status_code", 200] + - eq: ["body.args.foo1", "debugtalk"] + - eq: ["body.args.sum_v", "3"] + - eq: ["body.args.foo2", "bar21"] - name: post raw text variables: @@ -56,14 +44,8 @@ teststeps: Content-Type: "text/plain" body: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - 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 + - eq: ["status_code", 200] + - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."] - name: post form data variables: @@ -76,19 +58,7 @@ teststeps: Content-Type: "application/x-www-form-urlencoded" body: "foo1=$foo1&foo2=$foo2&foo3=$foo3" validate: - - check: status_code - assert: equal - expect: 200 - msg: check status_code - - check: body.form.foo1 - assert: equal - expect: $expect_foo1 - msg: check body.form.foo1 - - check: body.form.foo2 - assert: equal - expect: bar23 - msg: check body.form.foo2 - - check: body.form.foo3 - assert: equal - expect: bar21 - msg: check body.form.foo3 + - eq: ["status_code", 200] + - eq: ["body.form.foo1", "$expect_foo1"] + - eq: ["body.form.foo2", "bar23"] + - eq: ["body.form.foo3", "bar21"]