Skip to content

Commit 5422f23

Browse files
zeripathlafriks
authored andcommitted
Quieter Integration Tests (#6513)
* Rename BaseLogger to WriterLogger to help the creation of other providers * Don't export ColorBytes and ResetBytes from ColoredValues * Make integration tests only print logs if they fail * check can color before coloring * I always forget about MSSQL * Oh and use LEVEL in sqlite.ini * Make the test logger log at info - as it means you see the router * Remove empty expected changes * Make the migrations quieter too * Don't display SQL on error - it can be looked at in the file logs if necessary * Fix skip when using onGiteaRun
1 parent 7ed65a9 commit 5422f23

23 files changed

+607
-409
lines changed

docs/content/doc/advanced/logging-documentation.en-us.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ attributes should be cached if this is a commonly used log message.
357357
of bytes representing the color.
358358

359359
These functions will not double wrap a `log.ColoredValue`. They will
360-
also set the ResetBytes to the cached resetBytes.
360+
also set the `resetBytes` to the cached `resetBytes`.
361361

362-
Be careful not to change the contents of resetBytes or boldBytes as this
363-
will break rendering of logging elsewhere. You have been warned.
362+
The `colorBytes` and `resetBytes` are not exported to prevent
363+
accidental overwriting of internal values.
364364

365365
## Log Spoofing protection
366366

integrations/git_helper_for_declarative_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
5050
}
5151

5252
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
53-
prepareTestEnv(t)
53+
prepareTestEnv(t, 1)
5454
s := http.Server{
5555
Handler: mac,
5656
}

integrations/git_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func testGit(t *testing.T, u *url.URL) {
3838
u.Path = baseAPITestContext.GitPath()
3939

4040
t.Run("HTTP", func(t *testing.T) {
41+
PrintCurrentTest(t)
4142
httpContext := baseAPITestContext
4243
httpContext.Reponame = "repo-tmp-17"
4344

@@ -47,6 +48,7 @@ func testGit(t *testing.T, u *url.URL) {
4748
assert.NoError(t, err)
4849
defer os.RemoveAll(dstPath)
4950
t.Run("Standard", func(t *testing.T) {
51+
PrintCurrentTest(t)
5052
ensureAnonymousClone(t, u)
5153

5254
t.Run("CreateRepo", doAPICreateRepository(httpContext, false))
@@ -57,16 +59,21 @@ func testGit(t *testing.T, u *url.URL) {
5759
t.Run("Clone", doGitClone(dstPath, u))
5860

5961
t.Run("PushCommit", func(t *testing.T) {
62+
PrintCurrentTest(t)
6063
t.Run("Little", func(t *testing.T) {
64+
PrintCurrentTest(t)
6165
little = commitAndPush(t, littleSize, dstPath)
6266
})
6367
t.Run("Big", func(t *testing.T) {
68+
PrintCurrentTest(t)
6469
big = commitAndPush(t, bigSize, dstPath)
6570
})
6671
})
6772
})
6873
t.Run("LFS", func(t *testing.T) {
74+
PrintCurrentTest(t)
6975
t.Run("PushCommit", func(t *testing.T) {
76+
PrintCurrentTest(t)
7077
//Setup git LFS
7178
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath)
7279
assert.NoError(t, err)
@@ -76,17 +83,21 @@ func testGit(t *testing.T, u *url.URL) {
7683
assert.NoError(t, err)
7784

7885
t.Run("Little", func(t *testing.T) {
86+
PrintCurrentTest(t)
7987
littleLFS = commitAndPush(t, littleSize, dstPath)
8088
})
8189
t.Run("Big", func(t *testing.T) {
90+
PrintCurrentTest(t)
8291
bigLFS = commitAndPush(t, bigSize, dstPath)
8392
})
8493
})
8594
t.Run("Locks", func(t *testing.T) {
95+
PrintCurrentTest(t)
8696
lockTest(t, u.String(), dstPath)
8797
})
8898
})
8999
t.Run("Raw", func(t *testing.T) {
100+
PrintCurrentTest(t)
90101
session := loginUser(t, "user2")
91102

92103
// Request raw paths
@@ -110,6 +121,7 @@ func testGit(t *testing.T, u *url.URL) {
110121

111122
})
112123
t.Run("Media", func(t *testing.T) {
124+
PrintCurrentTest(t)
113125
session := loginUser(t, "user2")
114126

115127
// Request media paths
@@ -132,12 +144,14 @@ func testGit(t *testing.T, u *url.URL) {
132144

133145
})
134146
t.Run("SSH", func(t *testing.T) {
147+
PrintCurrentTest(t)
135148
sshContext := baseAPITestContext
136149
sshContext.Reponame = "repo-tmp-18"
137150
keyname := "my-testing-key"
138151
//Setup key the user ssh key
139152
withKeyFile(t, keyname, func(keyFile string) {
140153
t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile))
154+
PrintCurrentTest(t)
141155

142156
//Setup remote link
143157
sshURL := createSSHUrl(sshContext.GitPath(), u)
@@ -149,23 +163,29 @@ func testGit(t *testing.T, u *url.URL) {
149163
var little, big, littleLFS, bigLFS string
150164

151165
t.Run("Standard", func(t *testing.T) {
166+
PrintCurrentTest(t)
152167
t.Run("CreateRepo", doAPICreateRepository(sshContext, false))
153168

154169
//TODO get url from api
155170
t.Run("Clone", doGitClone(dstPath, sshURL))
156171

157172
//time.Sleep(5 * time.Minute)
158173
t.Run("PushCommit", func(t *testing.T) {
174+
PrintCurrentTest(t)
159175
t.Run("Little", func(t *testing.T) {
176+
PrintCurrentTest(t)
160177
little = commitAndPush(t, littleSize, dstPath)
161178
})
162179
t.Run("Big", func(t *testing.T) {
180+
PrintCurrentTest(t)
163181
big = commitAndPush(t, bigSize, dstPath)
164182
})
165183
})
166184
})
167185
t.Run("LFS", func(t *testing.T) {
186+
PrintCurrentTest(t)
168187
t.Run("PushCommit", func(t *testing.T) {
188+
PrintCurrentTest(t)
169189
//Setup git LFS
170190
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath)
171191
assert.NoError(t, err)
@@ -175,17 +195,21 @@ func testGit(t *testing.T, u *url.URL) {
175195
assert.NoError(t, err)
176196

177197
t.Run("Little", func(t *testing.T) {
198+
PrintCurrentTest(t)
178199
littleLFS = commitAndPush(t, littleSize, dstPath)
179200
})
180201
t.Run("Big", func(t *testing.T) {
202+
PrintCurrentTest(t)
181203
bigLFS = commitAndPush(t, bigSize, dstPath)
182204
})
183205
})
184206
t.Run("Locks", func(t *testing.T) {
207+
PrintCurrentTest(t)
185208
lockTest(t, u.String(), dstPath)
186209
})
187210
})
188211
t.Run("Raw", func(t *testing.T) {
212+
PrintCurrentTest(t)
189213
session := loginUser(t, "user2")
190214

191215
// Request raw paths
@@ -209,6 +233,7 @@ func testGit(t *testing.T, u *url.URL) {
209233

210234
})
211235
t.Run("Media", func(t *testing.T) {
236+
PrintCurrentTest(t)
212237
session := loginUser(t, "user2")
213238

214239
// Request media paths

integrations/integration_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ func initIntegrationTest() {
165165
routers.GlobalInit()
166166
}
167167

168-
func prepareTestEnv(t testing.TB) {
168+
func prepareTestEnv(t testing.TB, skip ...int) {
169+
ourSkip := 2
170+
if len(skip) > 0 {
171+
ourSkip += skip[0]
172+
}
173+
PrintCurrentTest(t, ourSkip)
169174
assert.NoError(t, models.LoadFixtures())
170175
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
171176
assert.NoError(t, os.RemoveAll(models.LocalCopyPath()))

integrations/migration-test/migration_test.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"database/sql"
1010
"fmt"
1111
"io/ioutil"
12-
"log"
1312
"os"
1413
"path"
1514
"regexp"
1615
"sort"
1716
"testing"
1817

18+
"code.gitea.io/gitea/integrations"
1919
"code.gitea.io/gitea/models"
2020
"code.gitea.io/gitea/models/migrations"
2121
"code.gitea.io/gitea/modules/setting"
@@ -26,21 +26,22 @@ import (
2626

2727
var currentEngine *xorm.Engine
2828

29-
func initMigrationTest() {
29+
func initMigrationTest(t *testing.T) {
30+
integrations.PrintCurrentTest(t, 2)
3031
giteaRoot := os.Getenv("GITEA_ROOT")
3132
if giteaRoot == "" {
32-
fmt.Println("Environment variable $GITEA_ROOT not set")
33+
integrations.Printf("Environment variable $GITEA_ROOT not set\n")
3334
os.Exit(1)
3435
}
3536
setting.AppPath = path.Join(giteaRoot, "gitea")
3637
if _, err := os.Stat(setting.AppPath); err != nil {
37-
fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)
38+
integrations.Printf("Could not find gitea binary at %s\n", setting.AppPath)
3839
os.Exit(1)
3940
}
4041

4142
giteaConf := os.Getenv("GITEA_CONF")
4243
if giteaConf == "" {
43-
fmt.Println("Environment variable $GITEA_CONF not set")
44+
integrations.Printf("Environment variable $GITEA_CONF not set\n")
4445
os.Exit(1)
4546
} else if !path.IsAbs(giteaConf) {
4647
setting.CustomConf = path.Join(giteaRoot, giteaConf)
@@ -51,6 +52,7 @@ func initMigrationTest() {
5152
setting.NewContext()
5253
setting.CheckLFSVersion()
5354
models.LoadConfigs()
55+
setting.NewLogServices(true)
5456
}
5557

5658
func getDialect() string {
@@ -125,7 +127,7 @@ func restoreOldDB(t *testing.T, version string) bool {
125127
data, err := readSQLFromFile(version)
126128
assert.NoError(t, err)
127129
if len(data) == 0 {
128-
log.Printf("No db found to restore for %s version: %s\n", models.DbCfg.Type, version)
130+
integrations.Printf("No db found to restore for %s version: %s\n", models.DbCfg.Type, version)
129131
return false
130132
}
131133

@@ -212,7 +214,8 @@ func wrappedMigrate(x *xorm.Engine) error {
212214
}
213215

214216
func doMigrationTest(t *testing.T, version string) {
215-
log.Printf("Performing migration test for %s version: %s", models.DbCfg.Type, version)
217+
integrations.PrintCurrentTest(t)
218+
integrations.Printf("Performing migration test for %s version: %s\n", models.DbCfg.Type, version)
216219
if !restoreOldDB(t, version) {
217220
return
218221
}
@@ -227,19 +230,22 @@ func doMigrationTest(t *testing.T, version string) {
227230
}
228231

229232
func TestMigrations(t *testing.T) {
230-
initMigrationTest()
233+
initMigrationTest(t)
231234

232235
dialect := models.DbCfg.Type
233236
versions, err := availableVersions()
234237
assert.NoError(t, err)
235238

236239
if len(versions) == 0 {
237-
log.Printf("No old database versions available to migration test for %s\n", dialect)
240+
integrations.Printf("No old database versions available to migration test for %s\n", dialect)
238241
return
239242
}
240243

241-
log.Printf("Preparing to test %d migrations for %s\n", len(versions), dialect)
244+
integrations.Printf("Preparing to test %d migrations for %s\n", len(versions), dialect)
242245
for _, version := range versions {
243-
doMigrationTest(t, version)
246+
t.Run(fmt.Sprintf("Migrate-%s-%s", dialect, version), func(t *testing.T) {
247+
doMigrationTest(t, version)
248+
})
249+
244250
}
245251
}

integrations/mssql.ini.tmpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ PROVIDER = file
6060
PROVIDER_CONFIG = data/sessions-mssql
6161

6262
[log]
63-
MODE = console,file
64-
ROOT_PATH = mssql-log
63+
MODE = test,file
64+
ROOT_PATH = sqlite-log
65+
REDIRECT_MACARON_LOG = true
66+
ROUTER = ,
67+
MACARON = ,
68+
XORM = file
6569

66-
[log.console]
67-
LEVEL = Warn
70+
[log.test]
71+
LEVEL = Info
72+
COLORIZE = true
6873

6974
[log.file]
70-
LEVEL = Debug
75+
LEVEL = Debug
7176

7277
[security]
7378
INSTALL_LOCK = true

integrations/mysql.ini.tmpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ PROVIDER = file
6060
PROVIDER_CONFIG = data/sessions-mysql
6161

6262
[log]
63-
MODE = console,file
64-
ROOT_PATH = mysql-log
63+
MODE = test,file
64+
ROOT_PATH = sqlite-log
65+
REDIRECT_MACARON_LOG = true
66+
ROUTER = ,
67+
MACARON = ,
68+
XORM = file
6569

66-
[log.console]
67-
LEVEL = Warn
70+
[log.test]
71+
LEVEL = Info
72+
COLORIZE = true
6873

6974
[log.file]
70-
LEVEL = Debug
75+
LEVEL = Debug
7176

7277
[security]
7378
INSTALL_LOCK = true

integrations/mysql8.ini.tmpl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@ PROVIDER = file
5757
PROVIDER_CONFIG = data/sessions-mysql8
5858

5959
[log]
60-
MODE = console,file
61-
ROOT_PATH = mysql8-log
60+
MODE = test,file
61+
ROOT_PATH = sqlite-log
62+
REDIRECT_MACARON_LOG = true
63+
ROUTER = ,
64+
MACARON = ,
65+
XORM = file
6266

63-
[log.console]
64-
LEVEL = Warn
67+
[log.test]
68+
LEVEL = Info
69+
COLORIZE = true
6570

6671
[log.file]
67-
LEVEL = Debug
72+
LEVEL = Debug
73+
6874

6975
[security]
7076
INSTALL_LOCK = true

integrations/pgsql.ini.tmpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ PROVIDER = file
6060
PROVIDER_CONFIG = data/sessions-pgsql
6161

6262
[log]
63-
MODE = console,file
64-
ROOT_PATH = pgsql-log
63+
MODE = test,file
64+
ROOT_PATH = sqlite-log
65+
REDIRECT_MACARON_LOG = true
66+
ROUTER = ,
67+
MACARON = ,
68+
XORM = file
6569

66-
[log.console]
67-
LEVEL = Warn
70+
[log.test]
71+
LEVEL = Info
72+
COLORIZE = true
6873

6974
[log.file]
70-
LEVEL = Debug
75+
LEVEL = Debug
7176

7277
[security]
7378
INSTALL_LOCK = true

0 commit comments

Comments
 (0)