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

Function Test_PreHooks_AllowsUserHookClientConfigMutation

client/core_test.go:426–449  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

424}
425
426func Test_PreHooks_AllowsUserHookClientConfigMutation(t *testing.T) {
427 t.Parallel()
428
429 client := New()
430 client.AddRequestHook(func(c *Client, _ *Request) error {
431 c.SetBaseURL("http://example.com")
432 c.SetPathParam("resource", "users")
433 c.SetParam("page", "1")
434 c.SetHeader("x-fiber-test", "ok")
435 c.SetCookie("session", "abc")
436 return nil
437 })
438
439 core := newCore()
440 core.client = client
441 core.req = AcquireRequest()
442 defer ReleaseRequest(core.req)
443 core.req.SetURL("/:resource")
444
445 require.NoError(t, core.preHooks())
446 require.Equal(t, "http://example.com/users?page=1", core.req.RawRequest.URI().String())
447 require.Equal(t, "ok", string(core.req.RawRequest.Header.Peek("x-fiber-test")))
448 require.Contains(t, string(core.req.RawRequest.Header.Cookie("session")), "abc")
449}
450
451// Test_AfterHooks_ReturnsUserHookError verifies a failing user response hook
452// aborts afterHooks and its error is propagated.

Callers

nothing calls this directly

Calls 15

newCoreFunction · 0.85
AcquireRequestFunction · 0.85
ReleaseRequestFunction · 0.85
AddRequestHookMethod · 0.80
SetBaseURLMethod · 0.80
SetURLMethod · 0.80
preHooksMethod · 0.80
URIMethod · 0.80
ContainsMethod · 0.80
NewFunction · 0.70
StringMethod · 0.65
CookieMethod · 0.65

Tested by

no test coverage detected