diff options
author | zeripath <art27@cantab.net> | 2022-06-03 07:14:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-03 02:14:09 -0400 |
commit | 085924b1b370310c989fa5e75bb33323746382b0 (patch) | |
tree | 41ff9baf8176378fe32d7f167cdf3d7f8b680302 | |
parent | e09fb30d34d1bab8ec51afa16745ea2d546f9355 (diff) | |
download | gitea-085924b1b370310c989fa5e75bb33323746382b0.tar.gz gitea-085924b1b370310c989fa5e75bb33323746382b0.zip |
Allow postgres integration tests to run over unix pipe (#19875)
-rw-r--r-- | integrations/integration_test.go | 21 | ||||
-rw-r--r-- | integrations/migration-test/migration_test.go | 32 |
2 files changed, 42 insertions, 11 deletions
diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 4df485a6e8..687591d5fa 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -193,8 +193,16 @@ func initIntegrationTest() { log.Fatal("db.Exec: %v", err) } case setting.Database.UsePostgreSQL: - db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s", - setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode)) + var db *sql.DB + var err error + if setting.Database.Host[0] == '/' { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@/%s?sslmode=%s&host=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Name, setting.Database.SSLMode, setting.Database.Host)) + } else { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + } + defer db.Close() if err != nil { log.Fatal("sql.Open: %v", err) @@ -216,8 +224,13 @@ func initIntegrationTest() { } db.Close() - db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", - setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + if setting.Database.Host[0] == '/' { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@/%s?sslmode=%s&host=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Name, setting.Database.SSLMode, setting.Database.Host)) + } else { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + } // This is a different db object; requires a different Close() defer db.Close() if err != nil { diff --git a/integrations/migration-test/migration_test.go b/integrations/migration-test/migration_test.go index 6e55807c27..6a431504a0 100644 --- a/integrations/migration-test/migration_test.go +++ b/integrations/migration-test/migration_test.go @@ -185,9 +185,17 @@ func restoreOldDB(t *testing.T, version string) bool { db.Close() case setting.Database.UsePostgreSQL: - db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s", - setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode)) - assert.NoError(t, err) + var db *sql.DB + var err error + if setting.Database.Host[0] == '/' { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@/?sslmode=%s&host=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.SSLMode, setting.Database.Host)) + assert.NoError(t, err) + } else { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode)) + assert.NoError(t, err) + } defer db.Close() _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name)) @@ -199,8 +207,13 @@ func restoreOldDB(t *testing.T, version string) bool { // Check if we need to setup a specific schema if len(setting.Database.Schema) != 0 { - db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", - setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + if setting.Database.Host[0] == '/' { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@/%s?sslmode=%s&host=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Name, setting.Database.SSLMode, setting.Database.Host)) + } else { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + } if !assert.NoError(t, err) { return false } @@ -225,8 +238,13 @@ func restoreOldDB(t *testing.T, version string) bool { db.Close() } - db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", - setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + if setting.Database.Host[0] == '/' { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@/%s?sslmode=%s&host=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Name, setting.Database.SSLMode, setting.Database.Host)) + } else { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + } assert.NoError(t, err) defer db.Close() |