From 3f2d907c9d48ad8a04894daacefb52c02c46232a Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 27 Mar 2022 11:35:41 +0800 Subject: [PATCH] refactor: relocate hrp tests --- examples/hrp/demo_test.py | 63 ------------------ examples/hrp/httpbin.json | 51 --------------- examples/hrp/plugin/debugtalk.go | 65 ------------------- examples/hrp/plugin/hashicorp.go | 18 ----- {examples/hrp => hrp/tests}/compat_test.go | 6 +- {examples/hrp => hrp/tests}/extract_test.go | 2 +- {examples/hrp => hrp/tests}/function_test.go | 2 +- .../hrp => hrp/tests}/rendezvous_test.go | 2 +- {examples/hrp => hrp/tests}/request_test.go | 2 +- {examples/hrp => hrp/tests}/validate_test.go | 2 +- {examples/hrp => hrp/tests}/variables_test.go | 2 +- 11 files changed, 9 insertions(+), 206 deletions(-) delete mode 100644 examples/hrp/demo_test.py delete mode 100644 examples/hrp/httpbin.json delete mode 100644 examples/hrp/plugin/debugtalk.go delete mode 100644 examples/hrp/plugin/hashicorp.go rename {examples/hrp => hrp/tests}/compat_test.go (69%) rename {examples/hrp => hrp/tests}/extract_test.go (99%) rename {examples/hrp => hrp/tests}/function_test.go (99%) rename {examples/hrp => hrp/tests}/rendezvous_test.go (98%) rename {examples/hrp => hrp/tests}/request_test.go (99%) rename {examples/hrp => hrp/tests}/validate_test.go (99%) rename {examples/hrp => hrp/tests}/variables_test.go (99%) diff --git a/examples/hrp/demo_test.py b/examples/hrp/demo_test.py deleted file mode 100644 index e2eddc1f..00000000 --- a/examples/hrp/demo_test.py +++ /dev/null @@ -1,63 +0,0 @@ -# NOTE: Generated By HttpRunner v3.1.6 -# FROM: hrp/examples/demo.json - - -from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase - - -class TestCaseDemo(HttpRunner): - - config = ( - Config("demo with complex mechanisms") - .variables( - **{ - "a": 12.3, - "b": 3.45, - "n": 5, - "varFoo1": "${gen_random_string($n)}", - "varFoo2": "${max($a, $b)}", - } - ) - .base_url("https://postman-echo.com") - ) - - teststeps = [ - Step( - RunRequest("get with params") - .with_variables(**{"b": 34.5, "n": 3, "varFoo2": "${max($a, $b)}"}) - .get("/get") - .with_params(**{"foo1": "$varFoo1", "foo2": "$varFoo2"}) - .with_headers(**{"User-Agent": "HttpRunnerPlus"}) - .extract() - .with_jmespath("body.args.foo1", "varFoo1") - .validate() - .assert_equal("status_code", 200) - .assert_equal('headers."Content-Type"', "application/json") - .assert_equal("body.args.foo1", 5) - .assert_equal("$varFoo1", 5) - .assert_equal("body.args.foo2", "34.5") - ), - Step( - RunRequest("post json data") - .post("/post") - .validate() - .assert_equal("status_code", 200) - .assert_equal("body.json.foo1", 5) - .assert_equal("body.json.foo2", 12.3) - ), - Step( - RunRequest("post form data") - .post("/post") - .with_headers( - **{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} - ) - .validate() - .assert_equal("status_code", 200) - .assert_equal("body.form.foo1", 5) - .assert_equal("body.form.foo2", "12.3") - ), - ] - - -if __name__ == "__main__": - TestCaseDemo().test_start() diff --git a/examples/hrp/httpbin.json b/examples/hrp/httpbin.json deleted file mode 100644 index 2bc11130..00000000 --- a/examples/hrp/httpbin.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "config": { - "name": "testcase description", - "variables": {}, - "verify": false - }, - "teststeps": [ - { - "name": "/get", - "request": { - "url": "http://httpbin.org/get", - "method": "GET", - "headers": { - "Host": "httpbin.org", - "Connection": "keep-alive", - "accept": "application/json", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.50", - "Referer": "http://httpbin.org/", - "Accept-Encoding": "gzip, deflate", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6" - } - }, - "validate": [ - { - "check": "status_code", - "assert": "equals", - "expect": 200, - "msg": "assert response status code" - }, - { - "check": "headers.\"Content-Type\"", - "assert": "equals", - "expect": "application/json", - "msg": "assert response header Content-Type" - }, - { - "check": "body.origin", - "assert": "equals", - "expect": "117.176.133.109", - "msg": "assert response body origin" - }, - { - "check": "body.url", - "assert": "equals", - "expect": "http://httpbin.org/get", - "msg": "assert response body url" - } - ] - } - ] -} \ No newline at end of file diff --git a/examples/hrp/plugin/debugtalk.go b/examples/hrp/plugin/debugtalk.go deleted file mode 100644 index 64cdc946..00000000 --- a/examples/hrp/plugin/debugtalk.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "fmt" - "log" -) - -func init() { - log.Println("plugin init function called") -} - -func SumTwoInt(a, b int) int { - return a + b -} - -func SumInts(args ...int) int { - var sum int - for _, arg := range args { - sum += arg - } - return sum -} - -func Sum(args ...interface{}) (interface{}, error) { - var sum float64 - for _, arg := range args { - switch v := arg.(type) { - case int: - sum += float64(v) - case float64: - sum += v - default: - return nil, fmt.Errorf("unexpected type: %T", arg) - } - } - return sum, nil -} - -func SumTwoString(a, b string) string { - return a + b -} - -func SumStrings(s ...string) string { - var sum string - for _, arg := range s { - sum += arg - } - return sum -} - -func Concatenate(args ...interface{}) (interface{}, error) { - var result string - for _, arg := range args { - result += fmt.Sprintf("%v", arg) - } - return result, nil -} - -func SetupHookExample(args string) string { - return fmt.Sprintf("step name: %v, setup...", args) -} - -func TeardownHookExample(args string) string { - return fmt.Sprintf("step name: %v, teardown...", args) -} diff --git a/examples/hrp/plugin/hashicorp.go b/examples/hrp/plugin/hashicorp.go deleted file mode 100644 index 4d09f339..00000000 --- a/examples/hrp/plugin/hashicorp.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "github.com/httprunner/funplugin/fungo" -) - -// register functions and build to plugin binary -func main() { - fungo.Register("sum_ints", SumInts) - fungo.Register("sum_two_int", SumTwoInt) - fungo.Register("sum", Sum) - fungo.Register("sum_two_string", SumTwoString) - fungo.Register("sum_strings", SumStrings) - fungo.Register("concatenate", Concatenate) - fungo.Register("setup_hook_example", SetupHookExample) - fungo.Register("teardown_hook_example", TeardownHookExample) - fungo.Serve() -} diff --git a/examples/hrp/compat_test.go b/hrp/tests/compat_test.go similarity index 69% rename from examples/hrp/compat_test.go rename to hrp/tests/compat_test.go index 336b30d6..74dc5fe0 100644 --- a/examples/hrp/compat_test.go +++ b/hrp/tests/compat_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing" @@ -8,8 +8,8 @@ import ( // generated by examples/data/har/demo.har using HttpRunner v3.1.6 var ( - demoHttpRunnerJSONPath hrp.TestCasePath = "demo_httprunner.json" - demoHttpRunnerYAMLPath hrp.TestCasePath = "demo_httprunner.yaml" + demoHttpRunnerJSONPath hrp.TestCasePath = "../../examples/hrp/demo_httprunner.json" + demoHttpRunnerYAMLPath hrp.TestCasePath = "../../examples/hrp/demo_httprunner.yaml" ) func TestCompatTestCase(t *testing.T) { diff --git a/examples/hrp/extract_test.go b/hrp/tests/extract_test.go similarity index 99% rename from examples/hrp/extract_test.go rename to hrp/tests/extract_test.go index ae29b623..e16f2a52 100644 --- a/examples/hrp/extract_test.go +++ b/hrp/tests/extract_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing" diff --git a/examples/hrp/function_test.go b/hrp/tests/function_test.go similarity index 99% rename from examples/hrp/function_test.go rename to hrp/tests/function_test.go index 0c2e8106..09dfa2f1 100644 --- a/examples/hrp/function_test.go +++ b/hrp/tests/function_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing" diff --git a/examples/hrp/rendezvous_test.go b/hrp/tests/rendezvous_test.go similarity index 98% rename from examples/hrp/rendezvous_test.go rename to hrp/tests/rendezvous_test.go index d8967f31..760e99cf 100644 --- a/examples/hrp/rendezvous_test.go +++ b/hrp/tests/rendezvous_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing" diff --git a/examples/hrp/request_test.go b/hrp/tests/request_test.go similarity index 99% rename from examples/hrp/request_test.go rename to hrp/tests/request_test.go index 75a76762..922734a1 100644 --- a/examples/hrp/request_test.go +++ b/hrp/tests/request_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing" diff --git a/examples/hrp/validate_test.go b/hrp/tests/validate_test.go similarity index 99% rename from examples/hrp/validate_test.go rename to hrp/tests/validate_test.go index 1a85d410..94922a98 100644 --- a/examples/hrp/validate_test.go +++ b/hrp/tests/validate_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing" diff --git a/examples/hrp/variables_test.go b/hrp/tests/variables_test.go similarity index 99% rename from examples/hrp/variables_test.go rename to hrp/tests/variables_test.go index d2a9f834..1bc73d6a 100644 --- a/examples/hrp/variables_test.go +++ b/hrp/tests/variables_test.go @@ -1,4 +1,4 @@ -package examples +package tests import ( "testing"