diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-09-01 19:26:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-01 11:26:07 +0000 |
commit | e8aae43f56fedd6f7b04affd378c2c4ed2af9d78 (patch) | |
tree | a9b03cbf3f926f2cd27eb4d3c18126aec1cc7aa9 /modules | |
parent | fcb4941d47217f3a369148d98b07e27205f385b8 (diff) | |
download | gitea-e8aae43f56fedd6f7b04affd378c2c4ed2af9d78.tar.gz gitea-e8aae43f56fedd6f7b04affd378c2c4ed2af9d78.zip |
Move web/api context related testing function into a separate package (#26859)
Just like `models/unittest`, the testing helper functions should be in a
separate package: `contexttest`
And complete the TODO:
> // TODO: move this function to other packages, because it depends on
"models" package
Diffstat (limited to 'modules')
-rw-r--r-- | modules/contexttest/context_tests.go (renamed from modules/test/context_tests.go) | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/modules/test/context_tests.go b/modules/contexttest/context_tests.go index 83e6117bcf..f8fb0859e3 100644 --- a/modules/test/context_tests.go +++ b/modules/contexttest/context_tests.go @@ -1,7 +1,8 @@ // Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package test +// Package contexttest provides utilities for testing Web/API contexts with models. +package contexttest import ( gocontext "context" @@ -22,7 +23,7 @@ import ( "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/web/middleware" - chi "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" ) @@ -40,7 +41,6 @@ func mockRequest(t *testing.T, reqPath string) *http.Request { } // MockContext mock context for unit tests -// TODO: move this function to other packages, because it depends on "models" package func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.ResponseRecorder) { resp := httptest.NewRecorder() req := mockRequest(t, reqPath) @@ -58,7 +58,6 @@ func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.Resp } // MockAPIContext mock context for unit tests -// TODO: move this function to other packages, because it depends on "models" package func MockAPIContext(t *testing.T, reqPath string) (*context.APIContext, *httptest.ResponseRecorder) { resp := httptest.NewRecorder() req := mockRequest(t, reqPath) @@ -123,7 +122,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) { } } -// LoadUser load a user into a test context. +// LoadUser load a user into a test context func LoadUser(t *testing.T, ctx gocontext.Context, userID int64) { doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}) switch ctx := ctx.(type) { |