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

Function Test_Request_Body_With_Server

client/request_test.go:1246–1460  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1244}
1245
1246func Test_Request_Body_With_Server(t *testing.T) {
1247 t.Parallel()
1248
1249 t.Run("json body", func(t *testing.T) {
1250 t.Parallel()
1251 testRequest(
1252 t,
1253 func(c fiber.Ctx) error {
1254 require.Equal(t, "application/json", string(c.Request().Header.ContentType()))
1255 return c.SendString(string(c.Request().Body()))
1256 },
1257 func(agent *Request) {
1258 agent.SetJSON(map[string]string{
1259 "success": "hello",
1260 })
1261 },
1262 "{\"success\":\"hello\"}",
1263 )
1264 })
1265
1266 t.Run("xml body", func(t *testing.T) {
1267 t.Parallel()
1268 testRequest(
1269 t,
1270 func(c fiber.Ctx) error {
1271 require.Equal(t, "application/xml", string(c.Request().Header.ContentType()))
1272 return c.SendString(string(c.Request().Body()))
1273 },
1274 func(agent *Request) {
1275 type args struct {
1276 Content string `xml:"content"`
1277 }
1278 agent.SetXML(args{
1279 Content: "hello",
1280 })
1281 },
1282 "<args><content>hello</content></args>",
1283 )
1284 })
1285
1286 t.Run("cbor body", func(t *testing.T) {
1287 t.Parallel()
1288 testRequest(
1289 t,
1290 func(c fiber.Ctx) error {
1291 require.Equal(t, "application/cbor", string(c.Request().Header.ContentType()))
1292 return c.SendString(string(c.Request().Body()))
1293 },
1294 func(agent *Request) {
1295 type args struct {
1296 Content string `cbor:"content"`
1297 }
1298 agent.SetCBOR(args{
1299 Content: "hello",
1300 })
1301 },
1302 "\xa1gcontentehello",
1303 )

Callers

nothing calls this directly

Calls 15

testRequestFunction · 0.85
createHelperServerFunction · 0.85
AcquireRequestFunction · 0.85
AcquireFileFunction · 0.85
SetFileNameFunction · 0.85
SetFileFieldNameFunction · 0.85
SetFileReaderFunction · 0.85
checkFormFileFunction · 0.85
SetFormDataWithMapMethod · 0.80
SetFormDataMethod · 0.80
AddFilesMethod · 0.80
SetBoundaryMethod · 0.80

Tested by

no test coverage detected