mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
feat: add http request with github.com/imroc/req
This commit is contained in:
1
go.mod
1
go.mod
@@ -6,6 +6,7 @@ require (
|
|||||||
github.com/StackExchange/wmi v1.2.1 // indirect
|
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
|
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/imroc/req v0.3.0 // indirect
|
||||||
github.com/myzhan/boomer v1.6.0
|
github.com/myzhan/boomer v1.6.0
|
||||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||||
github.com/shirou/gopsutil v3.21.8+incompatible // indirect
|
github.com/shirou/gopsutil v3.21.8+incompatible // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -8,6 +8,8 @@ github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
|||||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/imroc/req v0.3.0 h1:3EioagmlSG+z+KySToa+Ylo3pTFZs+jh3Brl7ngU12U=
|
||||||
|
github.com/imroc/req v0.3.0/go.mod h1:F+NZ+2EFSo6EFXdeIbpfE9hcC233id70kf0byW97Caw=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/myzhan/boomer v1.6.0 h1:xjgvmhDjgU9IEKnB7nU1HyoVEfj8SuuU3u6oY3Nugj0=
|
github.com/myzhan/boomer v1.6.0 h1:xjgvmhDjgU9IEKnB7nU1HyoVEfj8SuuU3u6oY3Nugj0=
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
tStepGET = RunRequest("get with params").
|
tStepGET = RunRequest("get with params").
|
||||||
GET("/get").
|
GET("https://postman-echo.com/get").
|
||||||
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
|
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
|
||||||
WithHeaders(Headers{"User-Agent": "HttpBoomer"}).
|
WithHeaders(Headers{"User-Agent": "HttpBoomer"}).
|
||||||
WithCookies(Cookies{"user": "debugtalk"}).
|
WithCookies(Cookies{"user": "debugtalk"}).
|
||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", 200, "check status code")
|
AssertEqual("status_code", 200, "check status code")
|
||||||
tStepPOSTData = RunRequest("post form data").
|
tStepPOSTData = RunRequest("post form data").
|
||||||
POST("/post").
|
POST("https://postman-echo.com/post").
|
||||||
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
|
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
|
||||||
WithHeaders(Headers{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
|
WithHeaders(Headers{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
|
||||||
WithData("a=1&b=2").
|
WithData("a=1&b=2").
|
||||||
|
|||||||
29
runner.go
29
runner.go
@@ -1,5 +1,11 @@
|
|||||||
package httpboomer
|
package httpboomer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/imroc/req"
|
||||||
|
)
|
||||||
|
|
||||||
func HttpRunner() *Runner {
|
func HttpRunner() *Runner {
|
||||||
return &Runner{}
|
return &Runner{}
|
||||||
}
|
}
|
||||||
@@ -17,6 +23,7 @@ func (r *Runner) Run(testcases ...*TestCase) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runCase(testcase *TestCase) error {
|
func (r *Runner) runCase(testcase *TestCase) error {
|
||||||
|
// config := testcase.Config
|
||||||
for _, step := range testcase.TestSteps {
|
for _, step := range testcase.TestSteps {
|
||||||
if err := r.runStep(step); err != nil {
|
if err := r.runStep(step); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -32,3 +39,25 @@ func (r *Runner) runStep(req IStep) error {
|
|||||||
func (r *Runner) GetSummary() *TestCaseSummary {
|
func (r *Runner) GetSummary() *TestCaseSummary {
|
||||||
return &TestCaseSummary{}
|
return &TestCaseSummary{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (step *TStep) Run() error {
|
||||||
|
|
||||||
|
var v []interface{}
|
||||||
|
v = append(v, req.Header(step.Request.Headers))
|
||||||
|
v = append(v, req.Param(step.Request.Params))
|
||||||
|
|
||||||
|
for cookieName, cookieValue := range step.Request.Cookies {
|
||||||
|
v = append(v, &http.Cookie{
|
||||||
|
Name: cookieName,
|
||||||
|
Value: cookieValue,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Debug = true
|
||||||
|
resp, err := req.Do(string(step.Request.Method), step.Request.URL, v...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp.Response().Body.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user