Skip to content

Commit 10ebd4d

Browse files
Copilotgaby
andauthored
🐛 bug: make cache post test distinct
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/c0423e5f-7f46-4ba0-ba0b-ef41c6eb7933 Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
1 parent 2470124 commit 10ebd4d

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

middleware/cache/cache_test.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -936,37 +936,32 @@ func Test_Cache_Post(t *testing.T) {
936936

937937
app.Use(New())
938938

939+
count := 0
939940
app.Post("/", func(c fiber.Ctx) error {
940-
return c.SendString(fiber.Query[string](c, "cache"))
941-
})
942-
943-
app.Get("/get", func(c fiber.Ctx) error {
944-
return c.SendString(fiber.Query[string](c, "cache"))
941+
count++
942+
return c.SendString(fmt.Sprintf("%d:%s", count, fiber.Query[string](c, "cache")))
945943
})
946944

947945
resp, err := app.Test(httptest.NewRequest(fiber.MethodPost, "/?cache=123", http.NoBody))
948946
require.NoError(t, err)
949947
body, err := io.ReadAll(resp.Body)
950948
require.NoError(t, err)
951-
require.Equal(t, "123", string(body))
952-
953-
resp, err = app.Test(httptest.NewRequest(fiber.MethodPost, "/?cache=12345", http.NoBody))
954-
require.NoError(t, err)
955-
body, err = io.ReadAll(resp.Body)
956-
require.NoError(t, err)
957-
require.Equal(t, "12345", string(body))
949+
require.Equal(t, cacheUnreachable, resp.Header.Get("X-Cache"))
950+
require.Equal(t, "1:123", string(body))
958951

959-
resp, err = app.Test(httptest.NewRequest(fiber.MethodGet, "/get?cache=123", http.NoBody))
952+
resp, err = app.Test(httptest.NewRequest(fiber.MethodPost, "/?cache=123", http.NoBody))
960953
require.NoError(t, err)
961954
body, err = io.ReadAll(resp.Body)
962955
require.NoError(t, err)
963-
require.Equal(t, "123", string(body))
956+
require.Equal(t, cacheUnreachable, resp.Header.Get("X-Cache"))
957+
require.Equal(t, "2:123", string(body))
964958

965-
resp, err = app.Test(httptest.NewRequest(fiber.MethodGet, "/get?cache=12345", http.NoBody))
959+
resp, err = app.Test(httptest.NewRequest(fiber.MethodPost, "/?cache=12345", http.NoBody))
966960
require.NoError(t, err)
967961
body, err = io.ReadAll(resp.Body)
968962
require.NoError(t, err)
969-
require.Equal(t, "12345", string(body))
963+
require.Equal(t, cacheUnreachable, resp.Header.Get("X-Cache"))
964+
require.Equal(t, "3:12345", string(body))
970965
}
971966

972967
func Test_Cache_DefaultKeyDimensions(t *testing.T) {

0 commit comments

Comments
 (0)