mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
Merge branch 'master' of github.com:httprunner/httprunner
This commit is contained in:
@@ -39,11 +39,11 @@ const (
|
||||
)
|
||||
|
||||
func fmta(d time.Duration) string {
|
||||
return color.BlueString("%7dms", int(d.Milliseconds()))
|
||||
return color.YellowString("%7dms", int(d.Milliseconds()))
|
||||
}
|
||||
|
||||
func fmtb(d time.Duration) string {
|
||||
return color.MagentaString("%-9s", strconv.Itoa(int(d.Milliseconds()))+"ms")
|
||||
return color.RedString("%-9s", strconv.Itoa(int(d.Milliseconds()))+"ms")
|
||||
}
|
||||
|
||||
func grayscale(code color.Attribute) func(string, ...interface{}) string {
|
||||
@@ -137,7 +137,7 @@ func (s *Stat) Print() {
|
||||
if s.network != "" && s.addr != "" {
|
||||
printf("\n%s %s: %s\n",
|
||||
color.CyanString("Connected to"),
|
||||
color.YellowString(s.network),
|
||||
color.MagentaString(s.network),
|
||||
color.BlueString(s.addr),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/httprunner/funplugin/shared"
|
||||
"github.com/pkg/errors"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
type PluginType string
|
||||
@@ -23,6 +25,13 @@ const (
|
||||
Go PluginType = "go"
|
||||
)
|
||||
|
||||
type ProjectInfo struct {
|
||||
ProjectName string `json:"project_name,omitempty" yaml:"project_name,omitempty"`
|
||||
ProjectPath string `json:"project_path,omitempty" yaml:"project_path,omitempty"`
|
||||
CreateTime time.Time `json:"create_time,omitempty" yaml:"create_time,omitempty"`
|
||||
Version string `json:"hrp_version,omitempty" yaml:"hrp_version,omitempty"`
|
||||
}
|
||||
|
||||
//go:embed templates/*
|
||||
var templatesDir embed.FS
|
||||
|
||||
@@ -68,6 +77,12 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
|
||||
os.RemoveAll(projectName)
|
||||
}
|
||||
|
||||
// get project abs path
|
||||
projectPath, err := filepath.Abs(projectName)
|
||||
if err != nil {
|
||||
projectPath = projectName
|
||||
}
|
||||
|
||||
// create project folders
|
||||
if err := builtin.CreateFolder(projectName); err != nil {
|
||||
return err
|
||||
@@ -88,8 +103,21 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error
|
||||
return err
|
||||
}
|
||||
|
||||
projectInfo := &ProjectInfo{
|
||||
ProjectName: projectName,
|
||||
ProjectPath: projectPath,
|
||||
CreateTime: time.Now(),
|
||||
Version: version.VERSION,
|
||||
}
|
||||
|
||||
// dump project information to file
|
||||
err = builtin.Dump2JSON(projectInfo, filepath.Join(projectName, "proj.json"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create .gitignore
|
||||
err := CopyFile("templates/gitignore", filepath.Join(projectName, ".gitignore"))
|
||||
err = CopyFile("templates/gitignore", filepath.Join(projectName, ".gitignore"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -102,7 +130,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 +139,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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
-
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# NOTE: Generated By HttpRunner v4.0.0
|
||||
# FROM: testcases/demo_ref_testcase.yml
|
||||
# FROM: testcases/ref_testcase.yml
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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):
|
||||
|
||||
@@ -1 +1 @@
|
||||
v4.1.0-alpha
|
||||
v4.1.0-beta
|
||||
@@ -0,0 +1,12 @@
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func OpenWiki() error {
|
||||
log.Info().Msgf("%s https://httprunner.com", openCmd)
|
||||
return exec.Command(openCmd, "https://httprunner.com").Run()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package wiki
|
||||
|
||||
const openCmd = "open"
|
||||
@@ -0,0 +1,3 @@
|
||||
package wiki
|
||||
|
||||
const openCmd = "xdg-open"
|
||||
@@ -0,0 +1,3 @@
|
||||
package wiki
|
||||
|
||||
const openCmd = "explorer"
|
||||
Reference in New Issue
Block a user