Skip to content

Commit

Permalink
feat: add http request with github.com/imroc/req
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Sep 22, 2021
1 parent f19454d commit 5281ad7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // 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/olekukonko/tablewriter v0.0.5 // indirect
github.com/shirou/gopsutil v3.21.8+incompatible // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
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/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/myzhan/boomer v1.6.0 h1:xjgvmhDjgU9IEKnB7nU1HyoVEfj8SuuU3u6oY3Nugj0=
Expand Down
4 changes: 2 additions & 2 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

var (
tStepGET = RunRequest("get with params").
GET("/get").
GET("https://postman-echo.com/get").
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(Headers{"User-Agent": "HttpBoomer"}).
WithCookies(Cookies{"user": "debugtalk"}).
Validate().
AssertEqual("status_code", 200, "check status code")
tStepPOSTData = RunRequest("post form data").
POST("/post").
POST("https://postman-echo.com/post").
WithParams(Params{"foo1": "bar1", "foo2": "bar2"}).
WithHeaders(Headers{"User-Agent": "HttpBoomer", "Content-Type": "application/x-www-form-urlencoded"}).
WithData("a=1&b=2").
Expand Down
29 changes: 29 additions & 0 deletions runner.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package httpboomer

import (
"net/http"

"github.com/imroc/req"
)

func HttpRunner() *Runner {
return &Runner{}
}
Expand All @@ -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
Expand All @@ -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
}
5 changes: 0 additions & 5 deletions step.go

This file was deleted.

0 comments on commit 5281ad7

Please sign in to comment.