Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quieter Integration Tests #6513

Merged
merged 15 commits into from Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/content/doc/advanced/logging-documentation.en-us.md
Expand Up @@ -357,10 +357,10 @@ attributes should be cached if this is a commonly used log message.
of bytes representing the color.

These functions will not double wrap a `log.ColoredValue`. They will
also set the ResetBytes to the cached resetBytes.
also set the `resetBytes` to the cached `resetBytes`.

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

## Log Spoofing protection

Expand Down
2 changes: 1 addition & 1 deletion integrations/git_helper_for_declarative_test.go
Expand Up @@ -50,7 +50,7 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
}

func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
prepareTestEnv(t)
prepareTestEnv(t, 1)
s := http.Server{
Handler: mac,
}
Expand Down
25 changes: 25 additions & 0 deletions integrations/git_test.go
Expand Up @@ -38,6 +38,7 @@ func testGit(t *testing.T, u *url.URL) {
u.Path = baseAPITestContext.GitPath()

t.Run("HTTP", func(t *testing.T) {
PrintCurrentTest(t)
httpContext := baseAPITestContext
httpContext.Reponame = "repo-tmp-17"

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

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

t.Run("PushCommit", func(t *testing.T) {
PrintCurrentTest(t)
t.Run("Little", func(t *testing.T) {
PrintCurrentTest(t)
little = commitAndPush(t, littleSize, dstPath)
})
t.Run("Big", func(t *testing.T) {
PrintCurrentTest(t)
big = commitAndPush(t, bigSize, dstPath)
})
})
})
t.Run("LFS", func(t *testing.T) {
PrintCurrentTest(t)
t.Run("PushCommit", func(t *testing.T) {
PrintCurrentTest(t)
//Setup git LFS
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath)
assert.NoError(t, err)
Expand All @@ -76,17 +83,21 @@ func testGit(t *testing.T, u *url.URL) {
assert.NoError(t, err)

t.Run("Little", func(t *testing.T) {
PrintCurrentTest(t)
littleLFS = commitAndPush(t, littleSize, dstPath)
})
t.Run("Big", func(t *testing.T) {
PrintCurrentTest(t)
bigLFS = commitAndPush(t, bigSize, dstPath)
})
})
t.Run("Locks", func(t *testing.T) {
PrintCurrentTest(t)
lockTest(t, u.String(), dstPath)
})
})
t.Run("Raw", func(t *testing.T) {
PrintCurrentTest(t)
session := loginUser(t, "user2")

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

})
t.Run("Media", func(t *testing.T) {
PrintCurrentTest(t)
session := loginUser(t, "user2")

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

})
t.Run("SSH", func(t *testing.T) {
PrintCurrentTest(t)
sshContext := baseAPITestContext
sshContext.Reponame = "repo-tmp-18"
keyname := "my-testing-key"
//Setup key the user ssh key
withKeyFile(t, keyname, func(keyFile string) {
t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile))
PrintCurrentTest(t)

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

t.Run("Standard", func(t *testing.T) {
PrintCurrentTest(t)
t.Run("CreateRepo", doAPICreateRepository(sshContext, false))

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

//time.Sleep(5 * time.Minute)
t.Run("PushCommit", func(t *testing.T) {
PrintCurrentTest(t)
t.Run("Little", func(t *testing.T) {
PrintCurrentTest(t)
little = commitAndPush(t, littleSize, dstPath)
})
t.Run("Big", func(t *testing.T) {
PrintCurrentTest(t)
big = commitAndPush(t, bigSize, dstPath)
})
})
})
t.Run("LFS", func(t *testing.T) {
PrintCurrentTest(t)
t.Run("PushCommit", func(t *testing.T) {
PrintCurrentTest(t)
//Setup git LFS
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath)
assert.NoError(t, err)
Expand All @@ -175,17 +195,21 @@ func testGit(t *testing.T, u *url.URL) {
assert.NoError(t, err)

t.Run("Little", func(t *testing.T) {
PrintCurrentTest(t)
littleLFS = commitAndPush(t, littleSize, dstPath)
})
t.Run("Big", func(t *testing.T) {
PrintCurrentTest(t)
bigLFS = commitAndPush(t, bigSize, dstPath)
})
})
t.Run("Locks", func(t *testing.T) {
PrintCurrentTest(t)
lockTest(t, u.String(), dstPath)
})
})
t.Run("Raw", func(t *testing.T) {
PrintCurrentTest(t)
session := loginUser(t, "user2")

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

})
t.Run("Media", func(t *testing.T) {
PrintCurrentTest(t)
session := loginUser(t, "user2")

// Request media paths
Expand Down
7 changes: 6 additions & 1 deletion integrations/integration_test.go
Expand Up @@ -165,7 +165,12 @@ func initIntegrationTest() {
routers.GlobalInit()
}

func prepareTestEnv(t testing.TB) {
func prepareTestEnv(t testing.TB, skip ...int) {
ourSkip := 2
if len(skip) > 0 {
ourSkip += skip[0]
}
PrintCurrentTest(t, ourSkip)
assert.NoError(t, models.LoadFixtures())
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
assert.NoError(t, os.RemoveAll(models.LocalCopyPath()))
Expand Down
28 changes: 17 additions & 11 deletions integrations/migration-test/migration_test.go
Expand Up @@ -9,13 +9,13 @@ import (
"database/sql"
"fmt"
"io/ioutil"
"log"
"os"
"path"
"regexp"
"sort"
"testing"

"code.gitea.io/gitea/integrations"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/setting"
Expand All @@ -26,21 +26,22 @@ import (

var currentEngine *xorm.Engine

func initMigrationTest() {
func initMigrationTest(t *testing.T) {
integrations.PrintCurrentTest(t, 2)
giteaRoot := os.Getenv("GITEA_ROOT")
if giteaRoot == "" {
fmt.Println("Environment variable $GITEA_ROOT not set")
integrations.Printf("Environment variable $GITEA_ROOT not set\n")
os.Exit(1)
}
setting.AppPath = path.Join(giteaRoot, "gitea")
if _, err := os.Stat(setting.AppPath); err != nil {
fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)
integrations.Printf("Could not find gitea binary at %s\n", setting.AppPath)
os.Exit(1)
}

giteaConf := os.Getenv("GITEA_CONF")
if giteaConf == "" {
fmt.Println("Environment variable $GITEA_CONF not set")
integrations.Printf("Environment variable $GITEA_CONF not set\n")
os.Exit(1)
} else if !path.IsAbs(giteaConf) {
setting.CustomConf = path.Join(giteaRoot, giteaConf)
Expand All @@ -51,6 +52,7 @@ func initMigrationTest() {
setting.NewContext()
setting.CheckLFSVersion()
models.LoadConfigs()
setting.NewLogServices(true)
}

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

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

func doMigrationTest(t *testing.T, version string) {
log.Printf("Performing migration test for %s version: %s", models.DbCfg.Type, version)
integrations.PrintCurrentTest(t)
integrations.Printf("Performing migration test for %s version: %s\n", models.DbCfg.Type, version)
if !restoreOldDB(t, version) {
return
}
Expand All @@ -227,19 +230,22 @@ func doMigrationTest(t *testing.T, version string) {
}

func TestMigrations(t *testing.T) {
initMigrationTest()
initMigrationTest(t)

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

if len(versions) == 0 {
log.Printf("No old database versions available to migration test for %s\n", dialect)
integrations.Printf("No old database versions available to migration test for %s\n", dialect)
return
}

log.Printf("Preparing to test %d migrations for %s\n", len(versions), dialect)
integrations.Printf("Preparing to test %d migrations for %s\n", len(versions), dialect)
for _, version := range versions {
doMigrationTest(t, version)
t.Run(fmt.Sprintf("Migrate-%s-%s", dialect, version), func(t *testing.T) {
doMigrationTest(t, version)
})

}
}
15 changes: 10 additions & 5 deletions integrations/mssql.ini.tmpl
Expand Up @@ -60,14 +60,19 @@ PROVIDER = file
PROVIDER_CONFIG = data/sessions-mssql

[log]
MODE = console,file
ROOT_PATH = mssql-log
MODE = test,file
ROOT_PATH = sqlite-log
REDIRECT_MACARON_LOG = true
ROUTER = ,
MACARON = ,
XORM = file

[log.console]
LEVEL = Warn
[log.test]
LEVEL = Info
COLORIZE = true

[log.file]
LEVEL = Debug
LEVEL = Debug

[security]
INSTALL_LOCK = true
Expand Down
15 changes: 10 additions & 5 deletions integrations/mysql.ini.tmpl
Expand Up @@ -60,14 +60,19 @@ PROVIDER = file
PROVIDER_CONFIG = data/sessions-mysql

[log]
MODE = console,file
ROOT_PATH = mysql-log
MODE = test,file
ROOT_PATH = sqlite-log
REDIRECT_MACARON_LOG = true
ROUTER = ,
MACARON = ,
XORM = file

[log.console]
LEVEL = Warn
[log.test]
LEVEL = Info
COLORIZE = true

[log.file]
LEVEL = Debug
LEVEL = Debug

[security]
INSTALL_LOCK = true
Expand Down
16 changes: 11 additions & 5 deletions integrations/mysql8.ini.tmpl
Expand Up @@ -57,14 +57,20 @@ PROVIDER = file
PROVIDER_CONFIG = data/sessions-mysql8

[log]
MODE = console,file
ROOT_PATH = mysql8-log
MODE = test,file
ROOT_PATH = sqlite-log
REDIRECT_MACARON_LOG = true
ROUTER = ,
MACARON = ,
XORM = file

[log.console]
LEVEL = Warn
[log.test]
LEVEL = Info
COLORIZE = true

[log.file]
LEVEL = Debug
LEVEL = Debug


[security]
INSTALL_LOCK = true
Expand Down
15 changes: 10 additions & 5 deletions integrations/pgsql.ini.tmpl
Expand Up @@ -60,14 +60,19 @@ PROVIDER = file
PROVIDER_CONFIG = data/sessions-pgsql

[log]
MODE = console,file
ROOT_PATH = pgsql-log
MODE = test,file
ROOT_PATH = sqlite-log
REDIRECT_MACARON_LOG = true
ROUTER = ,
MACARON = ,
XORM = file

[log.console]
LEVEL = Warn
[log.test]
LEVEL = Info
COLORIZE = true

[log.file]
LEVEL = Debug
LEVEL = Debug

[security]
INSTALL_LOCK = true
Expand Down