diff --git a/go.mod b/go.mod index e39aff3..0b5ada3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 4943d53..ce77521 100644 --- a/go.sum +++ b/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/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= diff --git a/request_test.go b/request_test.go index ff2eb5c..7d66508 100644 --- a/request_test.go +++ b/request_test.go @@ -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"). diff --git a/runner.go b/runner.go index eba8ccf..a054cf1 100644 --- a/runner.go +++ b/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 +} diff --git a/step.go b/step.go deleted file mode 100644 index 7d9aa79..0000000 --- a/step.go +++ /dev/null @@ -1,5 +0,0 @@ -package httpboomer - -func (step *TStep) Run() error { - return nil -}