use helper function to create test db connection for planned pg support

This commit is contained in:
Brad Rydzewski 2015-10-19 11:45:53 -07:00
parent 505ec312b5
commit ffd42a1a0e
10 changed files with 46 additions and 41 deletions

View file

@ -8,7 +8,7 @@ import (
)
func TestBuild(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -8,7 +8,7 @@ import (
)
func TestJob(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -8,7 +8,7 @@ import (
)
func TestKey(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -10,7 +10,7 @@ import (
)
func TestLog(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -8,7 +8,7 @@ import (
)
func TestNode(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -8,7 +8,7 @@ import (
)
func TestRepostore(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -8,7 +8,7 @@ import (
)
func TestUserstore(t *testing.T) {
db := database.Open("sqlite3", ":memory:")
db := database.OpenTest()
defer db.Close()
g := goblin.Goblin(t)

View file

@ -4,28 +4,20 @@ import (
"code.google.com/p/go.net/context"
)
const reqkey = "remote"
const key = "remote"
// NewContext returns a Context whose Value method returns
// the applications Remote instance.
func NewContext(parent context.Context, v Remote) context.Context {
return &wrapper{parent, v}
}
type wrapper struct {
context.Context
v Remote
}
// Value returns the named key from the context.
func (c *wrapper) Value(key interface{}) interface{} {
if key == reqkey {
return c.v
}
return c.Context.Value(key)
// Setter defines a context that enables setting values.
type Setter interface {
Set(string, interface{})
}
// FromContext returns the Remote associated with this context.
func FromContext(c context.Context) Remote {
return c.Value(reqkey).(Remote)
return c.Value(key).(Remote)
}
// ToContext adds the Remote to this context if it supports
// the Setter interface.
func ToContext(c Setter, r Remote) {
c.Set(key, r)
}

View file

@ -4,6 +4,7 @@ package database
import (
"database/sql"
"os"
"github.com/drone/drone/shared/envconfig"
@ -49,3 +50,15 @@ func Open(driver, config string) *sql.DB {
}
return db
}
func OpenTest() *sql.DB {
var (
driver = "sqlite3"
config = ":memory:"
)
if os.Getenv("DATABASE_DRIVER") != "" {
driver = os.Getenv("DATABASE_DRIVER")
config = os.Getenv("DATABASE_CONFIG")
}
return Open(driver, config)
}

View file

@ -2,15 +2,15 @@
CREATE TABLE users (
user_id SERIAL PRIMARY KEY
,user_login VARCHAR(500)
,user_token VARCHAR(500)
,user_secret VARCHAR(500)
,user_login VARCHAR(40)
,user_token VARCHAR(128)
,user_secret VARCHAR(128)
,user_expiry INTEGER
,user_email VARCHAR(500)
,user_avatar VARCHAR(500)
,user_email VARCHAR(256)
,user_avatar VARCHAR(256)
,user_active BOOLEAN
,user_admin BOOLEAN
,user_hash VARCHAR(500)
,user_hash VARCHAR(128)
,UNIQUE(user_login)
);
@ -60,21 +60,21 @@ CREATE TABLE builds (
build_id SERIAL PRIMARY KEY
,build_repo_id INTEGER
,build_number INTEGER
,build_event VARCHAR(500)
,build_status VARCHAR(500)
,build_event VARCHAR(25)
,build_status VARCHAR(25)
,build_enqueued INTEGER
,build_created INTEGER
,build_started INTEGER
,build_finished INTEGER
,build_commit VARCHAR(500)
,build_branch VARCHAR(500)
,build_ref VARCHAR(500)
,build_refspec VARCHAR(1000)
,build_remote VARCHAR(500)
,build_commit VARCHAR(40)
,build_branch VARCHAR(256)
,build_ref VARCHAR(512)
,build_refspec VARCHAR(512)
,build_remote VARCHAR(512)
,build_title VARCHAR(1000)
,build_message VARCHAR(2000)
,build_timestamp INTEGER
,build_author VARCHAR(500)
,build_author VARCHAR(40)
,build_avatar VARCHAR(1000)
,build_email VARCHAR(500)
,build_link VARCHAR(1000)
@ -90,7 +90,7 @@ CREATE TABLE jobs (
,job_node_id INTEGER
,job_build_id INTEGER
,job_number INTEGER
,job_status VARCHAR(500)
,job_status VARCHAR(25)
,job_exit_code INTEGER
,job_started INTEGER
,job_enqueued INTEGER