mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 05:19:38 +08:00
feat: add http request with github.com/imroc/req
This commit is contained in:
29
runner.go
29
runner.go
@@ -1,5 +1,11 @@
|
||||
package httpboomer
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/imroc/req"
|
||||
)
|
||||
|
||||
func HttpRunner() *Runner {
|
||||
return &Runner{}
|
||||
}
|
||||
@@ -17,6 +23,7 @@ func (r *Runner) Run(testcases ...*TestCase) error {
|
||||
}
|
||||
|
||||
func (r *Runner) runCase(testcase *TestCase) error {
|
||||
// config := testcase.Config
|
||||
for _, step := range testcase.TestSteps {
|
||||
if err := r.runStep(step); err != nil {
|
||||
return err
|
||||
@@ -32,3 +39,25 @@ func (r *Runner) runStep(req IStep) error {
|
||||
func (r *Runner) GetSummary() *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