Improve middleware/requestid test suite (#2191)

Add a test scenario for client sent request id header.
This commit is contained in:
Lemuel Roberto Bonifácio 2023-08-21 14:12:54 -03:00 committed by GitHub
parent 6a449876e9
commit 6da1fe9cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}