mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 23:11:21 +08:00
feat: support v3 format debugtalk.py when executing hrp run/boom
This commit is contained in:
@@ -31,6 +31,7 @@ Copyright 2017 debugtalk
|
|||||||
|
|
||||||
* [hrp boom](hrp_boom.md) - run load test with boomer
|
* [hrp boom](hrp_boom.md) - run load test with boomer
|
||||||
* [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases
|
* [hrp convert](hrp_convert.md) - convert to JSON/YAML/gotest/pytest testcases
|
||||||
|
* [hrp build](hrp_build.md) - build plugin for testing
|
||||||
* [hrp har2case](hrp_har2case.md) - convert HAR to json/yaml testcase files
|
* [hrp har2case](hrp_har2case.md) - convert HAR to json/yaml testcase files
|
||||||
* [hrp pytest](hrp_pytest.md) - run API test with pytest
|
* [hrp pytest](hrp_pytest.md) - run API test with pytest
|
||||||
* [hrp run](hrp_run.md) - run API test with go engine
|
* [hrp run](hrp_run.md) - run API test with go engine
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ func GetVersion() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fungo.Register("get_version", GetVersion)
|
fungo.Register("GetVersion", GetVersion)
|
||||||
fungo.Register("sum_ints", SumInts)
|
fungo.Register("SumInts", SumInts)
|
||||||
fungo.Register("sum_two_int", SumTwoInt)
|
fungo.Register("SumTwoInt", SumTwoInt)
|
||||||
fungo.Register("sum_two", SumTwoInt)
|
fungo.Register("SumTwoInt", SumTwoInt)
|
||||||
fungo.Register("sum", Sum)
|
fungo.Register("Sum", Sum)
|
||||||
fungo.Register("setup_hook_example", SetupHookExample)
|
fungo.Register("SetupHookExample", SetupHookExample)
|
||||||
fungo.Register("teardown_hook_example", TeardownHookExample)
|
fungo.Register("TeardownHookExample", TeardownHookExample)
|
||||||
fungo.Serve()
|
fungo.Serve()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
"name": "demo with complex mechanisms",
|
"name": "demo with complex mechanisms",
|
||||||
"base_url": "https://postman-echo.com",
|
"base_url": "https://postman-echo.com",
|
||||||
"variables": {
|
"variables": {
|
||||||
"a": "${sum(10, 2.3)}",
|
"a": "${Sum(10, 2.3)}",
|
||||||
"b": 3.45,
|
"b": 3.45,
|
||||||
"n": "${sum_ints(1, 2, 2)}",
|
"n": "${SumInts(1, 2, 2)}",
|
||||||
"varFoo1": "${gen_random_string($n)}",
|
"varFoo1": "${gen_random_string($n)}",
|
||||||
"varFoo2": "${max($a, $b)}"
|
"varFoo2": "${max($a, $b)}"
|
||||||
}
|
}
|
||||||
@@ -38,10 +38,10 @@
|
|||||||
"varFoo2": "${max($a, $b)}"
|
"varFoo2": "${max($a, $b)}"
|
||||||
},
|
},
|
||||||
"setup_hooks": [
|
"setup_hooks": [
|
||||||
"${setup_hook_example($name)}"
|
"${SetupHookExample($name)}"
|
||||||
],
|
],
|
||||||
"teardown_hooks": [
|
"teardown_hooks": [
|
||||||
"${teardown_hook_example($name)}"
|
"${TeardownHookExample($name)}"
|
||||||
],
|
],
|
||||||
"extract": {
|
"extract": {
|
||||||
"varFoo1": "body.args.foo1"
|
"varFoo1": "body.args.foo1"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ teststeps:
|
|||||||
method: POST
|
method: POST
|
||||||
url: /post
|
url: /post
|
||||||
headers:
|
headers:
|
||||||
User-Agent: funplugin/${get_version()}
|
User-Agent: funplugin/${GetVersion()}
|
||||||
Content-Type: "application/x-www-form-urlencoded"
|
Content-Type: "application/x-www-form-urlencoded"
|
||||||
body: "foo1=$foo1&foo2=$foo3"
|
body: "foo1=$foo1&foo2=$foo3"
|
||||||
validate:
|
validate:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"variables": {
|
"variables": {
|
||||||
"foo1": "${ENV(USERNAME)}",
|
"foo1": "${ENV(USERNAME)}",
|
||||||
"foo2": "bar21",
|
"foo2": "bar21",
|
||||||
"sum_v": "${sum_two_int(1, 2)}"
|
"sum_v": "${SumTwoInt(1, 2)}"
|
||||||
},
|
},
|
||||||
"request": {
|
"request": {
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
"sum_v": "$sum_v"
|
"sum_v": "$sum_v"
|
||||||
},
|
},
|
||||||
"headers": {
|
"headers": {
|
||||||
"User-Agent": "funplugin/${get_version()}"
|
"User-Agent": "funplugin/${GetVersion()}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extract": {
|
"extract": {
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "/post",
|
"url": "/post",
|
||||||
"headers": {
|
"headers": {
|
||||||
"User-Agent": "funplugin/${get_version()}",
|
"User-Agent": "funplugin/${GetVersion()}",
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
},
|
},
|
||||||
"body": "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."
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "/post",
|
"url": "/post",
|
||||||
"headers": {
|
"headers": {
|
||||||
"User-Agent": "funplugin/${get_version()}",
|
"User-Agent": "funplugin/${GetVersion()}",
|
||||||
"Content-Type": "application/x-www-form-urlencoded"
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
},
|
},
|
||||||
"body": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
|
"body": "foo1=$foo1&foo2=$foo2&foo3=$foo3"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ teststeps:
|
|||||||
variables:
|
variables:
|
||||||
foo1: ${ENV(USERNAME)}
|
foo1: ${ENV(USERNAME)}
|
||||||
foo2: bar21
|
foo2: bar21
|
||||||
sum_v: "${sum_two_int(1, 2)}"
|
sum_v: "${SumTwoInt(1, 2)}"
|
||||||
request:
|
request:
|
||||||
method: GET
|
method: GET
|
||||||
url: $base_url/get
|
url: $base_url/get
|
||||||
@@ -23,7 +23,7 @@ teststeps:
|
|||||||
foo2: $foo2
|
foo2: $foo2
|
||||||
sum_v: $sum_v
|
sum_v: $sum_v
|
||||||
headers:
|
headers:
|
||||||
User-Agent: funplugin/${get_version()}
|
User-Agent: funplugin/${GetVersion()}
|
||||||
extract:
|
extract:
|
||||||
foo3: "body.args.foo2"
|
foo3: "body.args.foo2"
|
||||||
validate:
|
validate:
|
||||||
@@ -40,7 +40,7 @@ teststeps:
|
|||||||
method: POST
|
method: POST
|
||||||
url: $base_url/post
|
url: $base_url/post
|
||||||
headers:
|
headers:
|
||||||
User-Agent: funplugin/${get_version()}
|
User-Agent: funplugin/${GetVersion()}
|
||||||
Content-Type: "text/plain"
|
Content-Type: "text/plain"
|
||||||
body: "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:
|
validate:
|
||||||
@@ -54,7 +54,7 @@ teststeps:
|
|||||||
method: POST
|
method: POST
|
||||||
url: $base_url/post
|
url: $base_url/post
|
||||||
headers:
|
headers:
|
||||||
User-Agent: funplugin/${get_version()}
|
User-Agent: funplugin/${GetVersion()}
|
||||||
Content-Type: "application/x-www-form-urlencoded"
|
Content-Type: "application/x-www-form-urlencoded"
|
||||||
body: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
|
body: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
|
||||||
validate:
|
validate:
|
||||||
|
|||||||
15
examples/demo-with-no-fungo/.gitignore
vendored
Normal file
15
examples/demo-with-no-fungo/.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
.env
|
||||||
|
reports/
|
||||||
|
*.so
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
.DS_Store
|
||||||
|
output/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.python-version
|
||||||
|
logs/
|
||||||
|
|
||||||
|
# plugin
|
||||||
|
debugtalk.bin
|
||||||
|
debugtalk.so
|
||||||
0
examples/demo-with-no-fungo/har/.keep
Normal file
0
examples/demo-with-no-fungo/har/.keep
Normal file
@@ -1,10 +1,12 @@
|
|||||||
package examples
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
import "os"
|
func init() {
|
||||||
|
fmt.Println("init")
|
||||||
|
}
|
||||||
|
|
||||||
func SumTwoInt(a, b int) int {
|
func SumTwoInt(a, b int) int {
|
||||||
return a + b
|
return a + b
|
||||||
@@ -40,7 +42,3 @@ func SetupHookExample(args string) string {
|
|||||||
func TeardownHookExample(args string) string {
|
func TeardownHookExample(args string) string {
|
||||||
return fmt.Sprintf("step name: %v, teardown...", args)
|
return fmt.Sprintf("step name: %v, teardown...", args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
_, _ = os.Getwd()
|
|
||||||
}
|
|
||||||
176
examples/demo-with-no-fungo/testcases/demo.json
Normal file
176
examples/demo-with-no-fungo/testcases/demo.json
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"name": "demo with complex mechanisms",
|
||||||
|
"base_url": "https://postman-echo.com",
|
||||||
|
"variables": {
|
||||||
|
"a": "${Sum(10, 2.3)}",
|
||||||
|
"b": 3.45,
|
||||||
|
"n": "${SumInts(1, 2, 2)}",
|
||||||
|
"varFoo1": "${GenRandomString($n)}",
|
||||||
|
"varFoo2": "${Max($a, $b)}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"teststeps": [
|
||||||
|
{
|
||||||
|
"name": "transaction 1 start",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "start"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get with params",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "$varFoo2"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"User-Agent": "HttpRunnerPlus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"variables": {
|
||||||
|
"b": 34.5,
|
||||||
|
"n": 3,
|
||||||
|
"name": "get with params",
|
||||||
|
"varFoo2": "${Max($a, $b)}"
|
||||||
|
},
|
||||||
|
"setup_hooks": [
|
||||||
|
"${SetupHookExample($name)}"
|
||||||
|
],
|
||||||
|
"teardown_hooks": [
|
||||||
|
"${TeardownHookExample($name)}"
|
||||||
|
],
|
||||||
|
"extract": {
|
||||||
|
"varFoo1": "body.args.foo1"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check response status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "headers.\"Content-Type\"",
|
||||||
|
"assert": "startswith",
|
||||||
|
"expect": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.args.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "$varFoo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.args.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": "34.5",
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "transaction 1 end",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "end"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "post json data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "/post",
|
||||||
|
"body": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "${Max($a, $b)}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.json.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.json.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 12.3,
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "post form data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "/post",
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "${Max($a, $b)}",
|
||||||
|
"time": "${GetTimestamp()}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extract": {
|
||||||
|
"varTime": "body.form.time"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.form.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.form.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": "12.3",
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get with timestamp",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"time": "$varTime"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "body.args.time",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 13,
|
||||||
|
"msg": "check extracted var timestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
33
examples/demo-with-no-fungo/testcases/ref_testcase.yml
Normal file
33
examples/demo-with-no-fungo/testcases/ref_testcase.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
config:
|
||||||
|
name: "request methods testcase: reference testcase"
|
||||||
|
variables:
|
||||||
|
foo1: testsuite_config_bar1
|
||||||
|
expect_foo1: testsuite_config_bar1
|
||||||
|
expect_foo2: config_bar2
|
||||||
|
base_url: "https://postman-echo.com"
|
||||||
|
verify: False
|
||||||
|
|
||||||
|
teststeps:
|
||||||
|
-
|
||||||
|
name: request with functions
|
||||||
|
variables:
|
||||||
|
foo1: testcase_ref_bar1
|
||||||
|
expect_foo1: testcase_ref_bar1
|
||||||
|
testcase: testcases/requests.yml
|
||||||
|
export:
|
||||||
|
- foo3
|
||||||
|
-
|
||||||
|
name: post form data
|
||||||
|
variables:
|
||||||
|
foo1: bar1
|
||||||
|
request:
|
||||||
|
method: POST
|
||||||
|
url: /post
|
||||||
|
headers:
|
||||||
|
User-Agent: funplugin/${GetVersion()}
|
||||||
|
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"]
|
||||||
138
examples/demo-with-no-fungo/testcases/requests.json
Normal file
138
examples/demo-with-no-fungo/testcases/requests.json
Normal file
@@ -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": "${SumTwoInt(1, 2)}"
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"foo1": "$foo1",
|
||||||
|
"foo2": "$foo2",
|
||||||
|
"sum_v": "$sum_v"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"User-Agent": "funplugin/${GetVersion()}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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/${GetVersion()}",
|
||||||
|
"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/${GetVersion()}",
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
65
examples/demo-with-no-fungo/testcases/requests.yml
Normal file
65
examples/demo-with-no-fungo/testcases/requests.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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: "${SumTwoInt(1, 2)}"
|
||||||
|
request:
|
||||||
|
method: GET
|
||||||
|
url: /get
|
||||||
|
params:
|
||||||
|
foo1: $foo1
|
||||||
|
foo2: $foo2
|
||||||
|
sum_v: $sum_v
|
||||||
|
headers:
|
||||||
|
User-Agent: funplugin/${GetVersion()}
|
||||||
|
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/${GetVersion()}
|
||||||
|
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/${GetVersion()}
|
||||||
|
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"]
|
||||||
15
examples/demo-with-no-funppy/.gitignore
vendored
Normal file
15
examples/demo-with-no-funppy/.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
.env
|
||||||
|
reports/
|
||||||
|
*.so
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
.DS_Store
|
||||||
|
output/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.python-version
|
||||||
|
logs/
|
||||||
|
|
||||||
|
# plugin
|
||||||
|
debugtalk.bin
|
||||||
|
debugtalk.so
|
||||||
@@ -3,6 +3,10 @@ import time
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def get_version():
|
||||||
|
return "httprunner v4.0"
|
||||||
|
|
||||||
|
|
||||||
def sleep(n_secs):
|
def sleep(n_secs):
|
||||||
time.sleep(n_secs)
|
time.sleep(n_secs)
|
||||||
|
|
||||||
0
examples/demo-with-no-funppy/har/.keep
Normal file
0
examples/demo-with-no-funppy/har/.keep
Normal file
176
examples/demo-with-no-funppy/testcases/demo.json
Normal file
176
examples/demo-with-no-funppy/testcases/demo.json
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"name": "demo with complex mechanisms",
|
||||||
|
"base_url": "https://postman-echo.com",
|
||||||
|
"variables": {
|
||||||
|
"a": "${sum(10, 2.3)}",
|
||||||
|
"b": 3.45,
|
||||||
|
"n": "${sum_ints(1, 2, 2)}",
|
||||||
|
"varFoo1": "${gen_random_string($n)}",
|
||||||
|
"varFoo2": "${max($a, $b)}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"teststeps": [
|
||||||
|
{
|
||||||
|
"name": "transaction 1 start",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "start"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get with params",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "$varFoo2"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"User-Agent": "HttpRunnerPlus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"variables": {
|
||||||
|
"b": 34.5,
|
||||||
|
"n": 3,
|
||||||
|
"name": "get with params",
|
||||||
|
"varFoo2": "${max($a, $b)}"
|
||||||
|
},
|
||||||
|
"setup_hooks": [
|
||||||
|
"${setup_hook_example($name)}"
|
||||||
|
],
|
||||||
|
"teardown_hooks": [
|
||||||
|
"${teardown_hook_example($name)}"
|
||||||
|
],
|
||||||
|
"extract": {
|
||||||
|
"varFoo1": "body.args.foo1"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check response status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "headers.\"Content-Type\"",
|
||||||
|
"assert": "startswith",
|
||||||
|
"expect": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.args.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "$varFoo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.args.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": "34.5",
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "transaction 1 end",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "end"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "post json data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "/post",
|
||||||
|
"body": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "${max($a, $b)}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.json.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.json.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 12.3,
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "post form data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "/post",
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "${max($a, $b)}",
|
||||||
|
"time": "${get_timestamp()}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extract": {
|
||||||
|
"varTime": "body.form.time"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.form.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.form.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": "12.3",
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get with timestamp",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"time": "$varTime"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "body.args.time",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 13,
|
||||||
|
"msg": "check extracted var timestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
33
examples/demo-with-no-funppy/testcases/ref_testcase.yml
Normal file
33
examples/demo-with-no-funppy/testcases/ref_testcase.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
config:
|
||||||
|
name: "request methods testcase: reference testcase"
|
||||||
|
variables:
|
||||||
|
foo1: testsuite_config_bar1
|
||||||
|
expect_foo1: testsuite_config_bar1
|
||||||
|
expect_foo2: config_bar2
|
||||||
|
base_url: "https://postman-echo.com"
|
||||||
|
verify: False
|
||||||
|
|
||||||
|
teststeps:
|
||||||
|
-
|
||||||
|
name: request with functions
|
||||||
|
variables:
|
||||||
|
foo1: testcase_ref_bar1
|
||||||
|
expect_foo1: testcase_ref_bar1
|
||||||
|
testcase: testcases/requests.yml
|
||||||
|
export:
|
||||||
|
- foo3
|
||||||
|
-
|
||||||
|
name: post form data
|
||||||
|
variables:
|
||||||
|
foo1: bar1
|
||||||
|
request:
|
||||||
|
method: POST
|
||||||
|
url: /post
|
||||||
|
headers:
|
||||||
|
User-Agent: funplugin/${get_version()}
|
||||||
|
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"]
|
||||||
138
examples/demo-with-no-funppy/testcases/requests.json
Normal file
138
examples/demo-with-no-funppy/testcases/requests.json
Normal file
@@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
65
examples/demo-with-no-funppy/testcases/requests.yml
Normal file
65
examples/demo-with-no-funppy/testcases/requests.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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"]
|
||||||
@@ -25,7 +25,7 @@ func TestBoomerStandaloneRun(t *testing.T) {
|
|||||||
NewStep("TestCase3").CallRefCase(&TestCase{Config: NewConfig("TestCase3")}),
|
NewStep("TestCase3").CallRefCase(&TestCase{Config: NewConfig("TestCase3")}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testcase2 := &demoTestCaseWithPluginJSONPath
|
testcase2 := &demoTestCaseWithGoPluginJSONPath
|
||||||
|
|
||||||
b := NewBoomer(2, 1)
|
b := NewBoomer(2, 1)
|
||||||
go b.Run(testcase1, testcase2)
|
go b.Run(testcase1, testcase2)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func (t *TemplateContent) parseGoContent(path string) error {
|
|||||||
originalContent := string(content)
|
originalContent := string(content)
|
||||||
|
|
||||||
// parse imports
|
// parse imports
|
||||||
importSlice := t.Regexps.Import.FindAllStringSubmatch(originalContent, -1)
|
importSlice := t.Regexps.Imports.FindAllStringSubmatch(originalContent, -1)
|
||||||
if len(importSlice) != 0 {
|
if len(importSlice) != 0 {
|
||||||
imports := strings.Replace(importSlice[0][1], "\t", "", -1)
|
imports := strings.Replace(importSlice[0][1], "\t", "", -1)
|
||||||
for _, elem := range strings.Split(imports, "\n") {
|
for _, elem := range strings.Split(imports, "\n") {
|
||||||
@@ -70,7 +70,7 @@ func (t *TemplateContent) parseGoContent(path string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// parse import
|
// parse import
|
||||||
importSlice = t.Regexps.Imports.FindAllStringSubmatch(originalContent, -1)
|
importSlice = t.Regexps.Import.FindAllStringSubmatch(originalContent, -1)
|
||||||
if len(importSlice) != 0 {
|
if len(importSlice) != 0 {
|
||||||
for _, elem := range importSlice {
|
for _, elem := range importSlice {
|
||||||
t.Imports = append(t.Imports, strings.TrimSpace(elem[1]))
|
t.Imports = append(t.Imports, strings.TrimSpace(elem[1]))
|
||||||
|
|||||||
@@ -1,29 +1,51 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRun(t *testing.T) {
|
func TestRun(t *testing.T) {
|
||||||
err := Run("examples/debugtalk_no_funppy.py", "")
|
err := Run("../../../examples/demo-with-no-fungo/plugin/debugtalk.go", "")
|
||||||
if !assert.Nil(t, err) {
|
if !assert.Nil(t, err) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Run("examples/debugtalk_no_fungo.go", "")
|
err = Run("../../../examples/demo-with-no-funppy/debugtalk.py", "")
|
||||||
if !assert.Nil(t, err) {
|
if !assert.Nil(t, err) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Run("examples/debugtalk_no_funppy.py", "./debugtalk.py")
|
err = Run("../../../examples/demo-with-no-fungo/plugin/debugtalk.go", "./debugtalk_gen.bin")
|
||||||
if !assert.Nil(t, err) {
|
if !assert.Nil(t, err) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Run("examples/debugtalk_no_fungo.go", "./debugtalk_gen.bin")
|
err = Run("../../../examples/demo-with-no-funppy/debugtalk.py", "./debugtalk_gen.py")
|
||||||
if !assert.Nil(t, err) {
|
if !assert.Nil(t, err) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentBytes, err := builtin.ReadFile("./debugtalk_gen.py")
|
||||||
|
if !assert.Nil(t, err) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
content := string(contentBytes)
|
||||||
|
if !assert.Contains(t, content, "import funppy") {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !assert.Contains(t, content, "funppy.register") {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
|
||||||
|
reg, _ := regexp.Compile(`funppy\.register`)
|
||||||
|
matchedSlice := reg.FindAllStringSubmatch(content, -1)
|
||||||
|
if !assert.Len(t, matchedSlice, 10) {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ var ErrUnsupportedFileExt = fmt.Errorf("unsupported file extension")
|
|||||||
// LoadFile loads file content with file extension and assigns to structObj
|
// LoadFile loads file content with file extension and assigns to structObj
|
||||||
func LoadFile(path string, structObj interface{}) (err error) {
|
func LoadFile(path string, structObj interface{}) (err error) {
|
||||||
log.Info().Str("path", path).Msg("load file")
|
log.Info().Str("path", path).Msg("load file")
|
||||||
file, err := readFile(path)
|
file, err := ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "read file failed")
|
return errors.Wrap(err, "read file failed")
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ func parseEnvContent(file []byte, obj interface{}) error {
|
|||||||
|
|
||||||
func loadFromCSV(path string) []map[string]interface{} {
|
func loadFromCSV(path string) []map[string]interface{} {
|
||||||
log.Info().Str("path", path).Msg("load csv file")
|
log.Info().Str("path", path).Msg("load csv file")
|
||||||
file, err := readFile(path)
|
file, err := ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("read csv file failed")
|
log.Error().Err(err).Msg("read csv file failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -361,7 +361,7 @@ func loadFromCSV(path string) []map[string]interface{} {
|
|||||||
|
|
||||||
func loadMessage(path string) []byte {
|
func loadMessage(path string) []byte {
|
||||||
log.Info().Str("path", path).Msg("load message file")
|
log.Info().Str("path", path).Msg("load message file")
|
||||||
file, err := readFile(path)
|
file, err := ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("read message file failed")
|
log.Error().Err(err).Msg("read message file failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -369,7 +369,7 @@ func loadMessage(path string) []byte {
|
|||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFile(path string) ([]byte, error) {
|
func ReadFile(path string) ([]byte, error) {
|
||||||
var err error
|
var err error
|
||||||
path, err = filepath.Abs(path)
|
path, err = filepath.Abs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ func GetVersion() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fungo.Register("get_version", GetVersion)
|
fungo.Register("GetVersion", GetVersion)
|
||||||
fungo.Register("sum_ints", SumInts)
|
fungo.Register("SumInts", SumInts)
|
||||||
fungo.Register("sum_two_int", SumTwoInt)
|
fungo.Register("SumTwoInt", SumTwoInt)
|
||||||
fungo.Register("sum_two", SumTwoInt)
|
fungo.Register("SumTwoInt", SumTwoInt)
|
||||||
fungo.Register("sum", Sum)
|
fungo.Register("Sum", Sum)
|
||||||
fungo.Register("setup_hook_example", SetupHookExample)
|
fungo.Register("SetupHookExample", SetupHookExample)
|
||||||
fungo.Register("teardown_hook_example", TeardownHookExample)
|
fungo.Register("TeardownHookExample", TeardownHookExample)
|
||||||
fungo.Serve()
|
fungo.Serve()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
config:
|
||||||
|
name: "request methods testcase: reference testcase"
|
||||||
|
variables:
|
||||||
|
foo1: testsuite_config_bar1
|
||||||
|
expect_foo1: testsuite_config_bar1
|
||||||
|
expect_foo2: config_bar2
|
||||||
|
base_url: "https://postman-echo.com"
|
||||||
|
verify: False
|
||||||
|
|
||||||
|
teststeps:
|
||||||
|
-
|
||||||
|
name: request with functions
|
||||||
|
variables:
|
||||||
|
foo1: testcase_ref_bar1
|
||||||
|
expect_foo1: testcase_ref_bar1
|
||||||
|
testcase: testcases/requests.yml
|
||||||
|
export:
|
||||||
|
- foo3
|
||||||
|
-
|
||||||
|
name: post form data
|
||||||
|
variables:
|
||||||
|
foo1: bar1
|
||||||
|
request:
|
||||||
|
method: POST
|
||||||
|
url: /post
|
||||||
|
headers:
|
||||||
|
User-Agent: funplugin/${GetVersion()}
|
||||||
|
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"]
|
||||||
138
hrp/internal/scaffold/templates/testcases/demo_go_requests.json
Normal file
138
hrp/internal/scaffold/templates/testcases/demo_go_requests.json
Normal file
@@ -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": "${SumTwoInt(1, 2)}"
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"foo1": "$foo1",
|
||||||
|
"foo2": "$foo2",
|
||||||
|
"sum_v": "$sum_v"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"User-Agent": "funplugin/${GetVersion()}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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/${GetVersion()}",
|
||||||
|
"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/${GetVersion()}",
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
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: "${SumTwoInt(1, 2)}"
|
||||||
|
request:
|
||||||
|
method: GET
|
||||||
|
url: /get
|
||||||
|
params:
|
||||||
|
foo1: $foo1
|
||||||
|
foo2: $foo2
|
||||||
|
sum_v: $sum_v
|
||||||
|
headers:
|
||||||
|
User-Agent: funplugin/${GetVersion()}
|
||||||
|
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/${GetVersion()}
|
||||||
|
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/${GetVersion()}
|
||||||
|
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"]
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
{
|
||||||
|
"config": {
|
||||||
|
"name": "demo with complex mechanisms",
|
||||||
|
"base_url": "https://postman-echo.com",
|
||||||
|
"variables": {
|
||||||
|
"a": "${Sum(10, 2.3)}",
|
||||||
|
"b": 3.45,
|
||||||
|
"n": "${SumInts(1, 2, 2)}",
|
||||||
|
"varFoo1": "${gen_random_string($n)}",
|
||||||
|
"varFoo2": "${max($a, $b)}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"teststeps": [
|
||||||
|
{
|
||||||
|
"name": "transaction 1 start",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "start"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get with params",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "$varFoo2"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"User-Agent": "HttpRunnerPlus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"variables": {
|
||||||
|
"b": 34.5,
|
||||||
|
"n": 3,
|
||||||
|
"name": "get with params",
|
||||||
|
"varFoo2": "${max($a, $b)}"
|
||||||
|
},
|
||||||
|
"setup_hooks": [
|
||||||
|
"${SetupHookExample($name)}"
|
||||||
|
],
|
||||||
|
"teardown_hooks": [
|
||||||
|
"${TeardownHookExample($name)}"
|
||||||
|
],
|
||||||
|
"extract": {
|
||||||
|
"varFoo1": "body.args.foo1"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check response status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "headers.\"Content-Type\"",
|
||||||
|
"assert": "startswith",
|
||||||
|
"expect": "application/json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.args.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "$varFoo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.args.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": "34.5",
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "transaction 1 end",
|
||||||
|
"transaction": {
|
||||||
|
"name": "tran1",
|
||||||
|
"type": "end"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "post json data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "/post",
|
||||||
|
"body": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "${max($a, $b)}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.json.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.json.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 12.3,
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "post form data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": "/post",
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"foo1": "$varFoo1",
|
||||||
|
"foo2": "${max($a, $b)}",
|
||||||
|
"time": "${get_timestamp()}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extract": {
|
||||||
|
"varTime": "body.form.time"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "status_code",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": 200,
|
||||||
|
"msg": "check status code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.form.foo1",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 5,
|
||||||
|
"msg": "check args foo1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"check": "body.form.foo2",
|
||||||
|
"assert": "equals",
|
||||||
|
"expect": "12.3",
|
||||||
|
"msg": "check args foo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get with timestamp",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"url": "/get",
|
||||||
|
"params": {
|
||||||
|
"time": "$varTime"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{
|
||||||
|
"check": "body.args.time",
|
||||||
|
"assert": "length_equals",
|
||||||
|
"expect": 13,
|
||||||
|
"msg": "check extracted var timestamp"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@ package hrp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/build"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/httprunner/funplugin"
|
"github.com/httprunner/funplugin"
|
||||||
@@ -32,6 +34,21 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st
|
|||||||
// TODO: move pluginDir to funplugin
|
// TODO: move pluginDir to funplugin
|
||||||
pluginDir = filepath.Dir(pluginPath)
|
pluginDir = filepath.Dir(pluginPath)
|
||||||
|
|
||||||
|
// compatible the format of debugtalk.py with v2/v3
|
||||||
|
ext := filepath.Ext(pluginPath)
|
||||||
|
if ext == ".py" {
|
||||||
|
// skip if only debugtalk_gen.py exists
|
||||||
|
if !strings.HasSuffix(pluginPath, "debugtalk_gen.py") {
|
||||||
|
genPyPluginPath := filepath.Join(pluginDir, "debugtalk_gen.py")
|
||||||
|
err = build.Run(pluginPath, genPyPluginPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msgf(fmt.Sprintf("failed to build %s", pluginPath))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pluginPath = genPyPluginPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// found plugin file
|
// found plugin file
|
||||||
plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn))
|
plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,19 +79,19 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func locatePlugin(path string) (pluginPath string, err error) {
|
func locatePlugin(path string) (pluginPath string, err error) {
|
||||||
// priority: hashicorp plugin (debugtalk.bin > debugtalk_gen.py > debugtalk.py) > go plugin (debugtalk.so)
|
// priority: hashicorp plugin (debugtalk.bin > debugtalk.py > debugtalk_gen.py) > go plugin (debugtalk.so)
|
||||||
|
|
||||||
pluginPath, err = locateFile(path, hashicorpGoPluginFile)
|
pluginPath, err = locateFile(path, hashicorpGoPluginFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginPath, err = locateFile(path, hashicorpPyPluginFile)
|
pluginPath, err = locateFile(path, debugtalkPyFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginPath, err = locateFile(path, debugtalkPyFile)
|
pluginPath, err = locateFile(path, hashicorpPyPluginFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,22 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/build"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/scaffold"
|
"github.com/httprunner/httprunner/v4/hrp/internal/scaffold"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func buildHashicorpGoPluginWithNoFungo() {
|
||||||
|
log.Info().Msg("[init] build hashicorp go plugin")
|
||||||
|
err := build.Run(templatesDir+"noplugin/debugtalk.go", templatesDir+"debugtalk.bin")
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("build hashicorp go plugin failed")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func buildHashicorpGoPlugin() {
|
func buildHashicorpGoPlugin() {
|
||||||
log.Info().Msg("[init] build hashicorp go plugin")
|
log.Info().Msg("[init] build hashicorp go plugin")
|
||||||
err := builtin.ExecCommand("go", "build",
|
err := build.Run(templatesDir+"noplugin/debugtalk.go", templatesDir+"debugtalk.bin")
|
||||||
"-o", templatesDir+"debugtalk.bin", templatesDir+"plugin/debugtalk.go")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("build hashicorp go plugin failed")
|
log.Error().Err(err).Msg("build hashicorp go plugin failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -30,7 +38,7 @@ func removeHashicorpGoPlugin() {
|
|||||||
func buildHashicorpPyPlugin() {
|
func buildHashicorpPyPlugin() {
|
||||||
log.Info().Msg("[init] prepare hashicorp python plugin")
|
log.Info().Msg("[init] prepare hashicorp python plugin")
|
||||||
pluginFile := templatesDir + "debugtalk.py"
|
pluginFile := templatesDir + "debugtalk.py"
|
||||||
err := scaffold.CopyFile("templates/plugin/debugtalk.py", pluginFile)
|
err := scaffold.CopyFile("templates/noplugin/debugtalk.py", pluginFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("build hashicorp python plugin failed")
|
log.Error().Err(err).Msg("build hashicorp python plugin failed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -39,24 +47,14 @@ func buildHashicorpPyPlugin() {
|
|||||||
|
|
||||||
func removeHashicorpPyPlugin() {
|
func removeHashicorpPyPlugin() {
|
||||||
log.Info().Msg("[teardown] remove hashicorp python plugin")
|
log.Info().Msg("[teardown] remove hashicorp python plugin")
|
||||||
os.Remove(templatesDir + "debugtalk.py")
|
// on v4.1^, running case will generate debugtalk_gen.py used by python plugin
|
||||||
|
os.Remove(templatesDir + "debugtalk_gen.py")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunCaseWithGoPlugin(t *testing.T) {
|
func TestRunCaseWithGoPlugin(t *testing.T) {
|
||||||
buildHashicorpGoPlugin()
|
buildHashicorpGoPlugin()
|
||||||
defer removeHashicorpGoPlugin()
|
defer removeHashicorpGoPlugin()
|
||||||
|
|
||||||
assertRunTestCases(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRunCaseWithPythonPlugin(t *testing.T) {
|
|
||||||
buildHashicorpPyPlugin()
|
|
||||||
defer removeHashicorpPyPlugin()
|
|
||||||
|
|
||||||
assertRunTestCases(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertRunTestCases(t *testing.T) {
|
|
||||||
testcase1 := &TestCase{
|
testcase1 := &TestCase{
|
||||||
Config: NewConfig("TestCase1").
|
Config: NewConfig("TestCase1").
|
||||||
SetBaseURL("http://httpbin.org"),
|
SetBaseURL("http://httpbin.org"),
|
||||||
@@ -83,7 +81,7 @@ func assertRunTestCases(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithPluginJSONPath),
|
NewStep("testcase1-step4").CallRefCase(&demoTestCaseWithGoPluginJSONPath),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testcase2 := &TestCase{
|
testcase2 := &TestCase{
|
||||||
@@ -98,6 +96,18 @@ func assertRunTestCases(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunCaseWithPythonPlugin(t *testing.T) {
|
||||||
|
buildHashicorpPyPlugin()
|
||||||
|
defer removeHashicorpPyPlugin()
|
||||||
|
|
||||||
|
r := NewRunner(t)
|
||||||
|
r.SetPluginLogOn()
|
||||||
|
err := r.Run(&demoTestCaseWithPluginJSONPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("run testcase error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunCaseWithThinkTime(t *testing.T) {
|
func TestRunCaseWithThinkTime(t *testing.T) {
|
||||||
buildHashicorpGoPlugin()
|
buildHashicorpGoPlugin()
|
||||||
defer removeHashicorpGoPlugin()
|
defer removeHashicorpGoPlugin()
|
||||||
@@ -160,15 +170,15 @@ func TestRunCaseWithPluginJSON(t *testing.T) {
|
|||||||
buildHashicorpGoPlugin()
|
buildHashicorpGoPlugin()
|
||||||
defer removeHashicorpGoPlugin()
|
defer removeHashicorpGoPlugin()
|
||||||
|
|
||||||
err := NewRunner(nil).Run(&demoTestCaseWithPluginJSONPath) // hrp.Run(testCase)
|
err := NewRunner(nil).Run(&demoTestCaseWithGoPluginJSONPath) // hrp.Run(testCase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunCaseWithPluginYAML(t *testing.T) {
|
func TestRunCaseWithPluginYAML(t *testing.T) {
|
||||||
buildHashicorpGoPlugin()
|
buildHashicorpPyPlugin()
|
||||||
defer removeHashicorpGoPlugin()
|
defer removeHashicorpPyPlugin()
|
||||||
|
|
||||||
err := NewRunner(nil).Run(&demoTestCaseWithPluginYAMLPath) // hrp.Run(testCase)
|
err := NewRunner(nil).Run(&demoTestCaseWithPluginYAMLPath) // hrp.Run(testCase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
demoTestCaseWithPluginJSONPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.json"
|
demoTestCaseWithPluginJSONPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.json"
|
||||||
|
demoTestCaseWithGoPluginJSONPath TestCasePath = templatesDir + "testcases/demo_go_with_funplugin.json"
|
||||||
demoTestCaseWithPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.yaml"
|
demoTestCaseWithPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_with_funplugin.yaml"
|
||||||
demoTestCaseWithoutPluginJSONPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.json"
|
demoTestCaseWithoutPluginJSONPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.json"
|
||||||
demoTestCaseWithoutPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.yaml"
|
demoTestCaseWithoutPluginYAMLPath TestCasePath = templatesDir + "testcases/demo_without_funplugin.yaml"
|
||||||
|
|||||||
Reference in New Issue
Block a user