Skip to content

Instantly share code, notes, and snippets.

@mstrYoda
Created September 11, 2022 15:03
Show Gist options
  • Save mstrYoda/9a93477a79cfb3e97aaf9a73d1fe4e91 to your computer and use it in GitHub Desktop.
Save mstrYoda/9a93477a79cfb3e97aaf9a73d1fe4e91 to your computer and use it in GitHub Desktop.
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