Test_Redirect_CompleteFlowWithFlashMessages() — fiber Function Reference
Architecture documentation for the Test_Redirect_CompleteFlowWithFlashMessages() function in redirect_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 5a2df84c_af85_19c3_294b_bdc8361e071d["Test_Redirect_CompleteFlowWithFlashMessages()"] fee77792_8d65_0d02_107f_9a956c66b44c["redirect_test.go"] 5a2df84c_af85_19c3_294b_bdc8361e071d -->|defined in| fee77792_8d65_0d02_107f_9a956c66b44c b333a695_5de0_544d_4b7c_c7a4b752a688["assertFlashCookieCleared()"] 5a2df84c_af85_19c3_294b_bdc8361e071d -->|calls| b333a695_5de0_544d_4b7c_c7a4b752a688 style 5a2df84c_af85_19c3_294b_bdc8361e071d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
redirect_test.go lines 575–638
func Test_Redirect_CompleteFlowWithFlashMessages(t *testing.T) {
t.Parallel()
app := New()
// First handler that sets flash messages and redirects
app.Get("/source", func(c Ctx) error {
// Redirect to the target handler
return c.Redirect().With("string_message", "Hello, World!").
With("number_message", "12345").
With("bool_message", "true").
To("/target")
})
// Second handler that receives and processes flash messages
app.Get("/target", func(c Ctx) error {
// Get all flash messages and return them as a JSON response
return c.JSON(Map{
"string_message": c.Redirect().Message("string_message").Value,
"number_message": c.Redirect().Message("number_message").Value,
"bool_message": c.Redirect().Message("bool_message").Value,
})
})
// Step 1: Make the initial request to the source route
req := httptest.NewRequest(MethodGet, "/source", http.NoBody)
resp, err := app.Test(req)
require.NoError(t, err)
require.Equal(t, StatusSeeOther, resp.StatusCode)
require.Equal(t, "/target", resp.Header.Get(HeaderLocation))
// Verify and get the cookie from the response
cookies := resp.Cookies()
var flashCookie *http.Cookie
for _, cookie := range cookies {
if cookie.Name == "fiber_flash" {
flashCookie = cookie
break
}
}
require.NotNil(t, flashCookie, "Flash cookie should be set")
// Step 2: Make the second request to the target route with the cookie
req = httptest.NewRequest(MethodGet, "/target", http.NoBody)
req.Header.Set("Cookie", flashCookie.Name+"="+flashCookie.Value)
resp, err = app.Test(req)
require.NoError(t, err)
require.Equal(t, StatusOK, resp.StatusCode)
assertFlashCookieCleared(t, resp.Header.Get(HeaderSetCookie))
// Parse the JSON response and verify flash messages
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var result map[string]any
err = json.Unmarshal(body, &result)
require.NoError(t, err)
// Verify all flash messages were received correctly
require.Equal(t, "Hello, World!", result["string_message"])
require.Equal(t, "12345", result["number_message"]) // JSON numbers are float64
require.Equal(t, "true", result["bool_message"])
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Redirect_CompleteFlowWithFlashMessages() do?
Test_Redirect_CompleteFlowWithFlashMessages() is a function in the fiber codebase, defined in redirect_test.go.
Where is Test_Redirect_CompleteFlowWithFlashMessages() defined?
Test_Redirect_CompleteFlowWithFlashMessages() is defined in redirect_test.go at line 575.
What does Test_Redirect_CompleteFlowWithFlashMessages() call?
Test_Redirect_CompleteFlowWithFlashMessages() calls 1 function(s): assertFlashCookieCleared.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free