mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
pushing my local branch
This commit is contained in:
32
server/database/testdatabase/testdatabase.go
Normal file
32
server/database/testdatabase/testdatabase.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package testdatabase
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
|
||||
// database drivers that may be tested
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var (
|
||||
driver = env("TEST_DB_DRIVER", "sqlite3")
|
||||
source = env("TEST_DB_SOURCE", ":memory:")
|
||||
)
|
||||
|
||||
// Open opens a new database connection using a test
|
||||
// database environment, specified using the `$TEST_DB_DRIVER`
|
||||
// and `$TEST_DB_SOURCE` environment variables.
|
||||
func Open() (*sql.DB, error) {
|
||||
return sql.Open(driver, source)
|
||||
}
|
||||
|
||||
// helper function that retrieves the environment variable
|
||||
// if exists, else returns a default value.
|
||||
func env(name, def string) string {
|
||||
value := os.Getenv(name)
|
||||
if len(value) == 0 {
|
||||
value = def
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user