From cfce4e089e93896e943981a26bb833e6c8fd1f28 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 4 Mar 2024 11:38:52 +0800 Subject: [PATCH] Partial cherry-pick: a4859dcfea Improve user experience for outdated comments (#29050) --- services/contexttest/context_tests.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/contexttest/context_tests.go b/services/contexttest/context_tests.go index 068fbabf6..dbce80bfe 100644 --- a/services/contexttest/context_tests.go +++ b/services/contexttest/context_tests.go @@ -40,8 +40,19 @@ func mockRequest(t *testing.T, reqPath string) *http.Request { return req } +type MockContextOption struct { + Render context.Render +} + // MockContext mock context for unit tests -func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.ResponseRecorder) { +func MockContext(t *testing.T, reqPath string, opts ...MockContextOption) (*context.Context, *httptest.ResponseRecorder) { + var opt MockContextOption + if len(opts) > 0 { + opt = opts[0] + } + if opt.Render == nil { + opt.Render = &MockRender{} + } resp := httptest.NewRecorder() req := mockRequest(t, reqPath) base, baseCleanUp := context.NewBaseContext(resp, req)