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

Function Test_App_AutoHead_Compliance

app_test.go:1201–1238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1199}
1200
1201func Test_App_AutoHead_Compliance(t *testing.T) {
1202 t.Parallel()
1203
1204 app := New()
1205 app.Get("/hello", func(c Ctx) error {
1206 c.Set("X-Test", "string")
1207 return c.SendString("hello")
1208 })
1209 app.startupProcess()
1210
1211 getReq := httptest.NewRequest(MethodGet, "/hello", http.NoBody)
1212 getResp, err := app.Test(getReq)
1213 require.NoError(t, err, "app.Test(get)")
1214 defer func() {
1215 require.NoError(t, getResp.Body.Close())
1216 }()
1217
1218 body, err := io.ReadAll(getResp.Body)
1219 require.NoError(t, err)
1220 require.Equal(t, "hello", string(body))
1221 require.Equal(t, "string", getResp.Header.Get("X-Test"))
1222
1223 headReq := httptest.NewRequest(MethodHead, "/hello", http.NoBody)
1224 headResp, err := app.Test(headReq)
1225 require.NoError(t, err, "app.Test(head)")
1226 defer func() {
1227 require.NoError(t, headResp.Body.Close())
1228 }()
1229
1230 require.Equal(t, getResp.StatusCode, headResp.StatusCode)
1231 require.Equal(t, strconv.Itoa(len(body)), headResp.Header.Get(HeaderContentLength))
1232 require.Equal(t, getResp.Header.Get(HeaderContentType), headResp.Header.Get(HeaderContentType))
1233 require.Equal(t, getResp.Header.Get("X-Test"), headResp.Header.Get("X-Test"))
1234
1235 headBody, err := io.ReadAll(headResp.Body)
1236 require.NoError(t, err)
1237 require.Empty(t, headBody)
1238}
1239
1240func Test_App_AutoHead_Compliance_SendFile(t *testing.T) {
1241 t.Parallel()

Callers

nothing calls this directly

Calls 7

startupProcessMethod · 0.80
TestMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
SendStringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected