1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-24 19:24:26 +00:00

Merge pull request #59 from Fenny/master

Add Test
This commit is contained in:
Fenny 2020-02-05 20:46:49 -05:00 committed by GitHub
commit d0179381d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,8 @@ import (
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httputil"
"os"
"path/filepath"
"reflect"
@ -107,8 +109,24 @@ func getBytes(s string) (b []byte) {
return b
}
// FakeRequest creates a readWriter and calls ServeConn on local servver
func (r *Fiber) FakeRequest(raw string) (string, error) {
// FakeRequest is the same as Test
func (r *Fiber) FakeRequest(req interface{}) (string, error) {
return r.Test(req)
}
// Test creates a readWriter and calls ServeConn on local servver
func (r *Fiber) Test(req interface{}) (string, error) {
raw := ""
switch r := req.(type) {
case string:
raw = r
case *http.Request:
d, err := httputil.DumpRequest(r, true)
if err != nil {
return "", err
}
raw = getString(d)
}
server := &fasthttp.Server{
Handler: r.handler,
Name: r.Server,