[CHORE] Move test related function to own package

- Go's deadcode eliminator is quite simple, if you put a public function
in a package `aa/bb` that is used only by tests, it would still be built
if package `aa/bb` was imported. This means that if such functions use
libraries relevant only to tests that those libraries would still be
be built and increase the binary size of a Go binary.
- This is also the case with Forgejo, `models/migrations/base/tests.go`
contained functions exclusively used by tests which (skipping some steps
here) imports https://github.com/ClickHouse/clickhouse-go, which is
2MiB. The `code.gitea.io/gitea/models/migrations/base` package is
imported by `cmd/doctor` and thus the code of the clickhouse library is
also built and included in the Forgejo binary, although entirely unused
and not reachable.
- This patch moves the test-related functions to their own package, so
Go's deadcode eliminator knows not to build the test-related functions
and thus reduces the size of the Forgejo binary.
- It is not possible to move this to a `_test.go` file because Go does
not allow importing functions from such files, so any test helper
function must be in a non-test package and file.
- Reduction of size (built with `TAGS="sqlite sqlite_unlock_notify" make
build`):
  - Before: 95912040 bytes (92M)
  - After: 92306888 bytes (89M)
This commit is contained in:
Gusted 2024-07-14 15:34:42 +02:00
parent 6e83c39f13
commit 138942c09e
No known key found for this signature in database
GPG key ID: FD821B732837125F
38 changed files with 170 additions and 276 deletions

View file

@ -60,13 +60,6 @@ code.gitea.io/gitea/models/issues
IsErrIssueWasClosed
ChangeMilestoneStatus
code.gitea.io/gitea/models/migrations/base
removeAllWithRetry
newXORMEngine
deleteDB
PrepareTestEnv
MainTest
code.gitea.io/gitea/models/organization
GetTeamNamesByID
UpdateTeamUnits
@ -93,36 +86,6 @@ code.gitea.io/gitea/models/repo
GetTopicByName
WatchRepoMode
code.gitea.io/gitea/models/unittest
CheckConsistencyFor
checkForConsistency
GetXORMEngine
OverrideFixtures
InitFixtures
LoadFixtures
Copy
CopyDir
NewMockWebServer
NormalizedFullPath
FixturesDir
fatalTestError
InitSettings
MainTest
CreateTestEngine
PrepareTestDatabase
PrepareTestEnv
Cond
OrderBy
LoadBeanIfExists
BeanExists
AssertExistsAndLoadBean
GetCount
AssertNotExistsBean
AssertExistsIf
AssertSuccessfulInsert
AssertCount
AssertInt64InRange
code.gitea.io/gitea/models/user
IsErrPrimaryEmailCannotDelete
ErrUserInactive.Error
@ -273,22 +236,6 @@ code.gitea.io/gitea/modules/sync
StatusTable.Start
StatusTable.IsRunning
code.gitea.io/gitea/modules/testlogger
testLoggerWriterCloser.pushT
testLoggerWriterCloser.Log
testLoggerWriterCloser.recordError
testLoggerWriterCloser.printMsg
testLoggerWriterCloser.popT
testLoggerWriterCloser.Reset
PrintCurrentTest
Printf
NewTestLoggerWriter
TestLogEventWriter.Base
TestLogEventWriter.GetLevel
TestLogEventWriter.GetWriterName
TestLogEventWriter.GetWriterType
TestLogEventWriter.Run
code.gitea.io/gitea/modules/timeutil
GetExecutableModTime
MockSet