From 05e2bed02fbcf412ec5236524d4b85930a73273c Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 19 May 2022 20:55:51 +0800 Subject: [PATCH] change: startproject demo --- .github/workflows/hrp-scaffold.yml | 14 +- examples/demo-with-go-plugin/plugin/go.mod | 2 +- examples/demo-with-go-plugin/plugin/go.sum | 4 +- .../{demo_with_funplugin.json => demo.json} | 0 ...demo_ref_testcase.yml => ref_testcase.yml} | 2 +- .../testcases/requests.json | 138 ++++++++++++++++++ .../{demo_requests.yml => requests.yml} | 0 .../{demo_with_funplugin.json => demo.json} | 0 ...demo_ref_testcase.yml => ref_testcase.yml} | 2 +- .../testcases/requests.json | 138 ++++++++++++++++++ .../{demo_requests.yml => requests.yml} | 0 ...o_without_funplugin.json => requests.json} | 0 hrp/internal/scaffold/main.go | 13 +- .../templates/testcases/demo_ref_testcase.yml | 2 +- .../testcases/demo_ref_testcase_test.py | 2 +- .../templates/testcases/demo_requests.json | 138 ++++++++++++++++++ .../templates/testcases/demo_requests_test.py | 4 +- hrp/runner_test.go | 4 +- 18 files changed, 441 insertions(+), 22 deletions(-) rename examples/demo-with-go-plugin/testcases/{demo_with_funplugin.json => demo.json} (100%) rename examples/demo-with-go-plugin/testcases/{demo_ref_testcase.yml => ref_testcase.yml} (95%) create mode 100644 examples/demo-with-go-plugin/testcases/requests.json rename examples/demo-with-go-plugin/testcases/{demo_requests.yml => requests.yml} (100%) rename examples/demo-with-py-plugin/testcases/{demo_with_funplugin.json => demo.json} (100%) rename examples/demo-with-py-plugin/testcases/{demo_ref_testcase.yml => ref_testcase.yml} (95%) create mode 100644 examples/demo-with-py-plugin/testcases/requests.json rename examples/demo-with-py-plugin/testcases/{demo_requests.yml => requests.yml} (100%) rename examples/demo-without-plugin/testcases/{demo_without_funplugin.json => requests.json} (100%) create mode 100644 hrp/internal/scaffold/templates/testcases/demo_requests.json diff --git a/.github/workflows/hrp-scaffold.yml b/.github/workflows/hrp-scaffold.yml index 0d96ee00..08d2ee46 100644 --- a/.github/workflows/hrp-scaffold.yml +++ b/.github/workflows/hrp-scaffold.yml @@ -34,10 +34,10 @@ jobs: - name: Run generated demo tests run: ./output/hrp run demo/testcases/ - name: Run API test demo in examples - run: ./output/hrp run examples/demo-with-py-plugin/testcases/demo_with_funplugin.json + run: ./output/hrp run examples/demo-with-py-plugin/testcases/demo.json - name: Run load test demo in examples run: | - ./output/hrp boom examples/demo-with-py-plugin/testcases/demo_with_funplugin.json --spawn-count 10 --spawn-rate 10 --loop-count 10 + ./output/hrp boom examples/demo-with-py-plugin/testcases/demo.json --spawn-count 10 --spawn-rate 10 --loop-count 10 scaffold-with-go-plugin: strategy: @@ -63,11 +63,11 @@ jobs: - name: Run API test demo in examples run: | go build -o examples/demo-with-go-plugin/debugtalk.bin examples/demo-with-go-plugin/plugin/debugtalk.go - ./output/hrp run examples/demo-with-go-plugin/testcases/demo_with_funplugin.json + ./output/hrp run examples/demo-with-go-plugin/testcases/demo.json - name: Run load test demo in examples run: | go build -o examples/demo-with-go-plugin/debugtalk.bin examples/demo-with-go-plugin/plugin/debugtalk.go - ./output/hrp boom examples/demo-with-go-plugin/testcases/demo_with_funplugin.json --spawn-count 10 --spawn-rate 10 --loop-count 10 + ./output/hrp boom examples/demo-with-go-plugin/testcases/demo.json --spawn-count 10 --spawn-rate 10 --loop-count 10 scaffold-without-custom-plugin: strategy: @@ -89,9 +89,9 @@ jobs: - name: Run start project run: ./output/hrp startproject demo --ignore-plugin - name: Run generated demo tests - run: ./output/hrp run demo/testcases/demo_without_funplugin.json + run: ./output/hrp run demo/testcases/requests.json - name: Run API test demo in examples - run: ./output/hrp run examples/demo-without-plugin/testcases/demo_without_funplugin.json + run: ./output/hrp run examples/demo-without-plugin/testcases/requests.json - name: Run load test demo in examples run: | - ./output/hrp boom examples/demo-without-plugin/testcases/demo_without_funplugin.json --spawn-count 10 --spawn-rate 10 --loop-count 10 + ./output/hrp boom examples/demo-without-plugin/testcases/requests.json --spawn-count 10 --spawn-rate 10 --loop-count 10 diff --git a/examples/demo-with-go-plugin/plugin/go.mod b/examples/demo-with-go-plugin/plugin/go.mod index 8dabb414..08a135d0 100644 --- a/examples/demo-with-go-plugin/plugin/go.mod +++ b/examples/demo-with-go-plugin/plugin/go.mod @@ -2,4 +2,4 @@ module plugin go 1.16 -require github.com/httprunner/funplugin v0.4.5 // indirect +require github.com/httprunner/funplugin v0.4.6 // indirect diff --git a/examples/demo-with-go-plugin/plugin/go.sum b/examples/demo-with-go-plugin/plugin/go.sum index 33c01bfb..59ea6478 100644 --- a/examples/demo-with-go-plugin/plugin/go.sum +++ b/examples/demo-with-go-plugin/plugin/go.sum @@ -58,8 +58,8 @@ github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/httprunner/funplugin v0.4.5 h1:2KCj5AZZA22OER6TN5P/PSBYFMiKpgTmCRbDmHB1tos= -github.com/httprunner/funplugin v0.4.5/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc= +github.com/httprunner/funplugin v0.4.6 h1:wwpjzo3G9a5BCXBkHs845w4ifKaCtVa/yQjREQjQOgo= +github.com/httprunner/funplugin v0.4.6/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc= github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= diff --git a/examples/demo-with-go-plugin/testcases/demo_with_funplugin.json b/examples/demo-with-go-plugin/testcases/demo.json similarity index 100% rename from examples/demo-with-go-plugin/testcases/demo_with_funplugin.json rename to examples/demo-with-go-plugin/testcases/demo.json diff --git a/examples/demo-with-go-plugin/testcases/demo_ref_testcase.yml b/examples/demo-with-go-plugin/testcases/ref_testcase.yml similarity index 95% rename from examples/demo-with-go-plugin/testcases/demo_ref_testcase.yml rename to examples/demo-with-go-plugin/testcases/ref_testcase.yml index 0743488e..6cf32323 100644 --- a/examples/demo-with-go-plugin/testcases/demo_ref_testcase.yml +++ b/examples/demo-with-go-plugin/testcases/ref_testcase.yml @@ -13,7 +13,7 @@ teststeps: variables: foo1: testcase_ref_bar1 expect_foo1: testcase_ref_bar1 - testcase: testcases/demo_requests.yml + testcase: testcases/requests.yml export: - foo3 - diff --git a/examples/demo-with-go-plugin/testcases/requests.json b/examples/demo-with-go-plugin/testcases/requests.json new file mode 100644 index 00000000..b13f3837 --- /dev/null +++ b/examples/demo-with-go-plugin/testcases/requests.json @@ -0,0 +1,138 @@ +{ + "config": { + "name": "request methods testcase with functions", + "variables": { + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2" + }, + "base_url": "https://postman-echo.com", + "verify": false, + "export": [ + "foo3" + ] + }, + "teststeps": [ + { + "name": "get with params", + "variables": { + "foo1": "bar11", + "foo2": "bar21", + "sum_v": "${sum_two_int(1, 2)}" + }, + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$foo1", + "foo2": "$foo2", + "sum_v": "$sum_v" + }, + "headers": { + "User-Agent": "funplugin/${get_version()}" + } + }, + "extract": { + "foo3": "body.args.foo2" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.args.foo1", + "bar11" + ] + }, + { + "eq": [ + "body.args.sum_v", + "3" + ] + }, + { + "eq": [ + "body.args.foo2", + "bar21" + ] + } + ] + }, + { + "name": "post raw text", + "variables": { + "foo1": "bar12", + "foo3": "bar32" + }, + "request": { + "method": "POST", + "url": "/post", + "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." + }, + "validate": [ + { + "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": { + "foo2": "bar23" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${get_version()}", + "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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/demo-with-go-plugin/testcases/demo_requests.yml b/examples/demo-with-go-plugin/testcases/requests.yml similarity index 100% rename from examples/demo-with-go-plugin/testcases/demo_requests.yml rename to examples/demo-with-go-plugin/testcases/requests.yml diff --git a/examples/demo-with-py-plugin/testcases/demo_with_funplugin.json b/examples/demo-with-py-plugin/testcases/demo.json similarity index 100% rename from examples/demo-with-py-plugin/testcases/demo_with_funplugin.json rename to examples/demo-with-py-plugin/testcases/demo.json diff --git a/examples/demo-with-py-plugin/testcases/demo_ref_testcase.yml b/examples/demo-with-py-plugin/testcases/ref_testcase.yml similarity index 95% rename from examples/demo-with-py-plugin/testcases/demo_ref_testcase.yml rename to examples/demo-with-py-plugin/testcases/ref_testcase.yml index 0743488e..6cf32323 100644 --- a/examples/demo-with-py-plugin/testcases/demo_ref_testcase.yml +++ b/examples/demo-with-py-plugin/testcases/ref_testcase.yml @@ -13,7 +13,7 @@ teststeps: variables: foo1: testcase_ref_bar1 expect_foo1: testcase_ref_bar1 - testcase: testcases/demo_requests.yml + testcase: testcases/requests.yml export: - foo3 - diff --git a/examples/demo-with-py-plugin/testcases/requests.json b/examples/demo-with-py-plugin/testcases/requests.json new file mode 100644 index 00000000..b13f3837 --- /dev/null +++ b/examples/demo-with-py-plugin/testcases/requests.json @@ -0,0 +1,138 @@ +{ + "config": { + "name": "request methods testcase with functions", + "variables": { + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2" + }, + "base_url": "https://postman-echo.com", + "verify": false, + "export": [ + "foo3" + ] + }, + "teststeps": [ + { + "name": "get with params", + "variables": { + "foo1": "bar11", + "foo2": "bar21", + "sum_v": "${sum_two_int(1, 2)}" + }, + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$foo1", + "foo2": "$foo2", + "sum_v": "$sum_v" + }, + "headers": { + "User-Agent": "funplugin/${get_version()}" + } + }, + "extract": { + "foo3": "body.args.foo2" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.args.foo1", + "bar11" + ] + }, + { + "eq": [ + "body.args.sum_v", + "3" + ] + }, + { + "eq": [ + "body.args.foo2", + "bar21" + ] + } + ] + }, + { + "name": "post raw text", + "variables": { + "foo1": "bar12", + "foo3": "bar32" + }, + "request": { + "method": "POST", + "url": "/post", + "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." + }, + "validate": [ + { + "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": { + "foo2": "bar23" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${get_version()}", + "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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/demo-with-py-plugin/testcases/demo_requests.yml b/examples/demo-with-py-plugin/testcases/requests.yml similarity index 100% rename from examples/demo-with-py-plugin/testcases/demo_requests.yml rename to examples/demo-with-py-plugin/testcases/requests.yml diff --git a/examples/demo-without-plugin/testcases/demo_without_funplugin.json b/examples/demo-without-plugin/testcases/requests.json similarity index 100% rename from examples/demo-without-plugin/testcases/demo_without_funplugin.json rename to examples/demo-without-plugin/testcases/requests.json diff --git a/hrp/internal/scaffold/main.go b/hrp/internal/scaffold/main.go index c4824f8b..ca505d68 100644 --- a/hrp/internal/scaffold/main.go +++ b/hrp/internal/scaffold/main.go @@ -102,7 +102,7 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error // create demo testcases if pluginType == Ignore { err := CopyFile("templates/testcases/demo_without_funplugin.json", - filepath.Join(projectName, "testcases", "demo_without_funplugin.json")) + filepath.Join(projectName, "testcases", "requests.json")) if err != nil { return err } @@ -111,17 +111,22 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error } err = CopyFile("templates/testcases/demo_with_funplugin.json", - filepath.Join(projectName, "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", "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", "demo_ref_testcase.yml")) + filepath.Join(projectName, "testcases", "ref_testcase.yml")) if err != nil { return err } diff --git a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml index 0743488e..6cf32323 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase.yml @@ -13,7 +13,7 @@ teststeps: variables: foo1: testcase_ref_bar1 expect_foo1: testcase_ref_bar1 - testcase: testcases/demo_requests.yml + testcase: testcases/requests.yml export: - foo3 - diff --git a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase_test.py b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase_test.py index 714030cd..ce77286e 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_ref_testcase_test.py +++ b/hrp/internal/scaffold/templates/testcases/demo_ref_testcase_test.py @@ -1,5 +1,5 @@ # NOTE: Generated By HttpRunner v4.0.0 -# FROM: testcases/demo_ref_testcase.yml +# FROM: testcases/ref_testcase.yml import sys diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.json b/hrp/internal/scaffold/templates/testcases/demo_requests.json new file mode 100644 index 00000000..b13f3837 --- /dev/null +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.json @@ -0,0 +1,138 @@ +{ + "config": { + "name": "request methods testcase with functions", + "variables": { + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2" + }, + "base_url": "https://postman-echo.com", + "verify": false, + "export": [ + "foo3" + ] + }, + "teststeps": [ + { + "name": "get with params", + "variables": { + "foo1": "bar11", + "foo2": "bar21", + "sum_v": "${sum_two_int(1, 2)}" + }, + "request": { + "method": "GET", + "url": "/get", + "params": { + "foo1": "$foo1", + "foo2": "$foo2", + "sum_v": "$sum_v" + }, + "headers": { + "User-Agent": "funplugin/${get_version()}" + } + }, + "extract": { + "foo3": "body.args.foo2" + }, + "validate": [ + { + "eq": [ + "status_code", + 200 + ] + }, + { + "eq": [ + "body.args.foo1", + "bar11" + ] + }, + { + "eq": [ + "body.args.sum_v", + "3" + ] + }, + { + "eq": [ + "body.args.foo2", + "bar21" + ] + } + ] + }, + { + "name": "post raw text", + "variables": { + "foo1": "bar12", + "foo3": "bar32" + }, + "request": { + "method": "POST", + "url": "/post", + "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." + }, + "validate": [ + { + "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": { + "foo2": "bar23" + }, + "request": { + "method": "POST", + "url": "/post", + "headers": { + "User-Agent": "funplugin/${get_version()}", + "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" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests_test.py b/hrp/internal/scaffold/templates/testcases/demo_requests_test.py index fc2ad5bb..6e05feb1 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests_test.py +++ b/hrp/internal/scaffold/templates/testcases/demo_requests_test.py @@ -1,8 +1,8 @@ # NOTE: Generated By HttpRunner v4.0.0 -# FROM: testcases/demo_requests.yml +# FROM: testcases/requests.yml -from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase +from httprunner import HttpRunner, Config, Step, RunRequest class TestCaseDemoRequests(HttpRunner): diff --git a/hrp/runner_test.go b/hrp/runner_test.go index 7ba1f4c2..2d743e6c 100644 --- a/hrp/runner_test.go +++ b/hrp/runner_test.go @@ -207,7 +207,7 @@ func TestLoadTestCases(t *testing.T) { if !assert.Nil(t, err) { t.Fatal() } - if !assert.Equal(t, len(testCases), 3) { + if !assert.Equal(t, len(testCases), 4) { t.Fatal() } @@ -217,7 +217,7 @@ func TestLoadTestCases(t *testing.T) { if !assert.Nil(t, err) { t.Fatal() } - if !assert.Equal(t, len(testCases), 3) { + if !assert.Equal(t, len(testCases), 4) { t.Fatal() }