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

Function Test_Query

client/client_test.go:1230–1278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1228}
1229
1230func Test_Query(t *testing.T) {
1231 t.Parallel()
1232
1233 setupApp := func() (*fiber.App, string) {
1234 app, addr := startTestServerWithPort(t, func(app *fiber.App) {
1235 app.Query("/", func(c fiber.Ctx) error {
1236 return c.Send(c.Body())
1237 })
1238 })
1239
1240 return app, addr
1241 }
1242
1243 t.Run("global query function", func(t *testing.T) {
1244 t.Parallel()
1245
1246 app, addr := setupApp()
1247 defer func() {
1248 require.NoError(t, app.Shutdown())
1249 }()
1250
1251 time.Sleep(1 * time.Second)
1252
1253 for range 5 {
1254 resp, err := Query("http://"+addr, Config{Body: "query body"})
1255
1256 require.NoError(t, err)
1257 require.Equal(t, fiber.StatusOK, resp.StatusCode())
1258 require.Equal(t, "query body", resp.String())
1259 }
1260 })
1261
1262 t.Run("client query", func(t *testing.T) {
1263 t.Parallel()
1264
1265 app, addr := setupApp()
1266 defer func() {
1267 require.NoError(t, app.Shutdown())
1268 }()
1269
1270 for range 5 {
1271 resp, err := New().Query("http://"+addr, Config{Body: "query body"})
1272
1273 require.NoError(t, err)
1274 require.Equal(t, fiber.StatusOK, resp.StatusCode())
1275 require.Equal(t, "query body", resp.String())
1276 }
1277 })
1278}
1279
1280func Test_Client_UserAgent(t *testing.T) {
1281 t.Parallel()

Callers

nothing calls this directly

Calls 9

startTestServerWithPortFunction · 0.85
ShutdownMethod · 0.80
QueryFunction · 0.70
NewFunction · 0.70
QueryMethod · 0.65
SendMethod · 0.65
BodyMethod · 0.65
StringMethod · 0.65
StatusCodeMethod · 0.45

Tested by

no test coverage detected