From 8adb6906d7864bae528f05e4627354adae6290a0 Mon Sep 17 00:00:00 2001 From: Ghost Date: Sat, 13 Jul 2024 22:03:50 +0800 Subject: [PATCH] chore: add ContextRenderRedirectWithEmptyPath test case --- context_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/context_test.go b/context_test.go index 8bbf270086..02c17a2d61 100644 --- a/context_test.go +++ b/context_test.go @@ -1222,6 +1222,18 @@ func TestContextRenderRedirectWith201(t *testing.T) { assert.Equal(t, "/resource", w.Header().Get("Location")) } +func TestContextRenderRedirectWithEmptyPath(t *testing.T) { + w := httptest.NewRecorder() + c, _ := CreateTestContext(w) + + c.Request, _ = http.NewRequest("POST", "http://example.com", nil) + c.Redirect(http.StatusTemporaryRedirect, "") + c.Writer.WriteHeaderNow() + + assert.Equal(t, http.StatusTemporaryRedirect, w.Code) + assert.Equal(t, "/", w.Header().Get("Location")) +} + func TestContextRenderRedirectAll(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) c.Request, _ = http.NewRequest("POST", "http://example.com", nil)