Created
September 11, 2022 15:03
-
-
Save mstrYoda/9a93477a79cfb3e97aaf9a73d1fe4e91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestFasthttpServer(t *testing.T) { | |
fSv := fasthttp.Server{} | |
fSv.Handler = func(ctx *fasthttp.RequestCtx) { | |
if string(ctx.Path()) == "/test" && string(ctx.Method()) == "GET" { | |
ctx.WriteString("OK") | |
} | |
} | |
ln := fasthttputil.NewInmemoryListener() | |
go fSv.Serve(ln) | |
client := http.Client{Transport: &http.Transport{ | |
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | |
return ln.Dial() | |
}, | |
}} | |
resp, _ := client.Get("http://localhost/test") | |
respBody, _ := io.ReadAll(resp.Body) | |
assert.Equal(t, string(respBody), "OK") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment