Skip to content

Commit

Permalink
Improve middleware/requestid test suite (#2191)
Browse files Browse the repository at this point in the history
Add a test scenario for client sent request id header.
  • Loading branch information
lemuelroberto authored Aug 21, 2023
1 parent 6a44987 commit 6da1fe9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions middleware/requestid/requestid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 6da1fe9

Please sign in to comment.