Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 575 Bytes

README.md

File metadata and controls

20 lines (18 loc) · 575 Bytes

Http testing

Example

// Init router 
var e *gin.Engine = // get form your gin router 
var testRouter = httptestutil.NewRouter(e)
...
    headers := map[string]string{"Authorization": "Bearer eyJh...."}
    rr := testRouter.POST(t, "/blah", `{"name":"my name"}`, headers)
    if rr.Code != http.StatusOK {
        t.Errorf("failed response code, buddy ...")
    }

Options

var defaultHeaders = map[string]string{"Authorization": "Bearer eyJh...."}
var testRouter = httptestutil.NewRouter(e).BasePath("/api/your-service").Headers(defaultHeaders)