MCPcopy
hub / github.com/gofiber/fiber / Test_App_BadRequest

Function Test_App_BadRequest

app_test.go:2709–2743  ·  view source on GitHub ↗

go test -run Test_App_BadRequest

(t *testing.T)

Source from the content-addressed store, hash-verified

2707
2708// go test -run Test_App_BadRequest
2709func Test_App_BadRequest(t *testing.T) {
2710 t.Parallel()
2711 app := New()
2712
2713 app.Get("/bad-request", func(c Ctx) error {
2714 return c.SendString("I should not be sent")
2715 })
2716
2717 ln, err := net.Listen(NetworkTCP4, "127.0.0.1:0")
2718 require.NoError(t, err)
2719 addr := ln.Addr().String()
2720
2721 go func() {
2722 time.Sleep(500 * time.Millisecond)
2723 conn, err := net.Dial(NetworkTCP4, addr)
2724 assert.NoError(t, err)
2725 defer func(conn net.Conn) {
2726 closeErr := conn.Close()
2727 assert.NoError(t, closeErr)
2728 }(conn)
2729
2730 _, err = conn.Write([]byte("BadRequest\r\n"))
2731 assert.NoError(t, err)
2732
2733 buf := make([]byte, 1024)
2734 var n int
2735 n, err = conn.Read(buf)
2736
2737 assert.NoError(t, err)
2738 assert.True(t, bytes.Contains(buf[:n], []byte("400 Bad Request")))
2739 assert.NoError(t, app.Shutdown())
2740 }()
2741
2742 require.NoError(t, app.Listener(ln, ListenConfig{DisableStartupMessage: true}))
2743}
2744
2745// go test -run Test_App_SmallReadBuffer
2746func Test_App_SmallReadBuffer(t *testing.T) {

Callers

nothing calls this directly

Calls 12

ListenMethod · 0.80
AddrMethod · 0.80
ContainsMethod · 0.80
ShutdownMethod · 0.80
ListenerMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
SendStringMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected