23/02/2020 - GO
If you have to set request context parameters in unit tests for your HTTP handler, you can use simple example below.
handler := your HTTP handler
r := httptest.NewRequest(http.MethodGet, "/api/v1/some/path", nil)
w := httptest.NewRecorder()
ctx := r.Context()
ctx = context.WithValue(ctx, "uuid", "some-uuid")
r = r.WithContext(ctx)
handler.Handle(w, r)
If you use code below in your handler, you will see that the some-uuid
is there.
fmt.Println(r.Context().Value("uuid"))