From b51a7118bdfabf70515d1be3f84f0cca3a2c3237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lemuel=20Roberto=20Bonif=C3=A1cio?= Date: Sat, 19 Aug 2023 21:51:37 -0300 Subject: [PATCH] Improve middleware/requestid test suite Add a test scenario for client sent request id header. --- middleware/requestid/requestid_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/middleware/requestid/requestid_test.go b/middleware/requestid/requestid_test.go index 523363c69..1bee3902d 100644 --- a/middleware/requestid/requestid_test.go +++ b/middleware/requestid/requestid_test.go @@ -55,9 +55,17 @@ func TestRequestID(t *testing.T) { changeID.Get("/", h) } + const expectedClientSentID = "client sent id" + clientSentID := app.Party("/client_id") + { + clientSentID.Use(requestid.New()) + clientSentID.Get("/", h) + } + e := httptest.New(t, app) e.GET("/default").Expect().Status(httptest.StatusOK).Body().NotEmpty() e.GET("/custom").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedCustomID) e.GET("/custom_err").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual(expectedErrMsg) e.GET("/custom_change_id").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedCustomIDFromOtherMiddleware) + e.GET("/client_id").WithHeader("X-Request-Id", expectedClientSentID).Expect().Header("X-Request-Id").IsEqual(expectedClientSentID) }