diff options
author | Jason Song | 2023-03-07 18:51:06 +0800 |
---|---|---|
committer | GitHub | 2023-03-07 18:51:06 +0800 |
commit | c84238800bb743181582f043ece9b44fef233c95 (patch) | |
tree | 83cf618233bb1a51c4a3325f8fa7662bb136afb1 /tests | |
parent | 84a299310d9a8f6387f18a1711485b7f33e6f6b5 (diff) |
Refactor `setting.Database.UseXXX` to methods (#23354)
Replace #23350.
Refactor `setting.Database.UseMySQL` to
`setting.Database.Type.IsMySQL()`.
To avoid mismatching between `Type` and `UseXXX`.
This refactor can fix the bug mentioned in #23350, so it should be
backported.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/markup_external_test.go | 2 | ||||
-rw-r--r-- | tests/integration/migration-test/migration_test.go | 10 | ||||
-rw-r--r-- | tests/test_utils.go | 6 |
3 files changed, 9 insertions, 9 deletions
diff --git a/tests/integration/markup_external_test.go b/tests/integration/markup_external_test.go index 6ea0226ec..c0e08a4f4 100644 --- a/tests/integration/markup_external_test.go +++ b/tests/integration/markup_external_test.go @@ -19,7 +19,7 @@ import ( func TestExternalMarkupRenderer(t *testing.T) { defer tests.PrepareTestEnv(t)() - if !setting.Database.UseSQLite3 { + if !setting.Database.Type.IsSQLite3() { t.Skip() return } diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go index f030f566c..4152379a9 100644 --- a/tests/integration/migration-test/migration_test.go +++ b/tests/integration/migration-test/migration_test.go @@ -94,7 +94,7 @@ func availableVersions() ([]string, error) { return nil, err } defer migrationsDir.Close() - versionRE, err := regexp.Compile("gitea-v(?P<version>.+)\\." + regexp.QuoteMeta(setting.Database.Type) + "\\.sql.gz") + versionRE, err := regexp.Compile("gitea-v(?P<version>.+)\\." + regexp.QuoteMeta(setting.Database.Type.String()) + "\\.sql.gz") if err != nil { return nil, err } @@ -149,7 +149,7 @@ func restoreOldDB(t *testing.T, version string) bool { } switch { - case setting.Database.UseSQLite3: + case setting.Database.Type.IsSQLite3(): util.Remove(setting.Database.Path) err := os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm) assert.NoError(t, err) @@ -162,7 +162,7 @@ func restoreOldDB(t *testing.T, version string) bool { assert.NoError(t, err) db.Close() - case setting.Database.UseMySQL: + case setting.Database.Type.IsMySQL(): db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/", setting.Database.User, setting.Database.Passwd, setting.Database.Host)) assert.NoError(t, err) @@ -184,7 +184,7 @@ func restoreOldDB(t *testing.T, version string) bool { assert.NoError(t, err) db.Close() - case setting.Database.UsePostgreSQL: + case setting.Database.Type.IsPostgreSQL(): var db *sql.DB var err error if setting.Database.Host[0] == '/' { @@ -252,7 +252,7 @@ func restoreOldDB(t *testing.T, version string) bool { assert.NoError(t, err) db.Close() - case setting.Database.UseMSSQL: + case setting.Database.Type.IsMSSQL(): host, port := setting.ParseMSSQLHostPort(setting.Database.Host) db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, "master", setting.Database.User, setting.Database.Passwd)) diff --git a/tests/test_utils.go b/tests/test_utils.go index 5cc31b814..e3e5becfb 100644 --- a/tests/test_utils.go +++ b/tests/test_utils.go @@ -74,7 +74,7 @@ func InitTest(requireGitea bool) { } switch { - case setting.Database.UseMySQL: + case setting.Database.Type.IsMySQL(): connType := "tcp" if len(setting.Database.Host) > 0 && setting.Database.Host[0] == '/' { // looks like a unix socket connType = "unix" @@ -89,7 +89,7 @@ func InitTest(requireGitea bool) { if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name)); err != nil { log.Fatal("db.Exec: %v", err) } - case setting.Database.UsePostgreSQL: + case setting.Database.Type.IsPostgreSQL(): var db *sql.DB var err error if setting.Database.Host[0] == '/' { @@ -146,7 +146,7 @@ func InitTest(requireGitea bool) { } } - case setting.Database.UseMSSQL: + case setting.Database.Type.IsMSSQL(): host, port := setting.ParseMSSQLHostPort(setting.Database.Host) db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, "master", setting.Database.User, setting.Database.Passwd)) |