github.com/abemedia/go-don@v0.2.2-0.20240329015135-be88e32bb73b/pkg/httptest/request.go (about)

     1  // Package httptest provides utilities for testing fasthttp handlers.
     2  package httptest
     3  
     4  import (
     5  	"strings"
     6  
     7  	"github.com/valyala/fasthttp"
     8  )
     9  
    10  // NewRequest returns a new [fasthttp.RequestCtx] with the given method, url, body and header.
    11  func NewRequest(method, url, body string, header map[string]string) *fasthttp.RequestCtx {
    12  	ctx := &fasthttp.RequestCtx{}
    13  	ctx.Request.Header.SetMethod(method)
    14  	ctx.Request.SetRequestURI(url)
    15  
    16  	for k, v := range header {
    17  		ctx.Request.Header.Set(k, v)
    18  	}
    19  
    20  	ctx.Request.SetBodyStream(strings.NewReader(body), len(body))
    21  
    22  	return ctx
    23  }