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
This commit is contained in:
parent
fcb4941d47
commit
e8aae43f56
21 changed files with 244 additions and 244 deletions
|
@ -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) {
|
Loading…
Add table
Add a link
Reference in a new issue