-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_util.go
43 lines (34 loc) · 884 Bytes
/
test_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package persistence
import (
"database/sql"
"testing"
)
func failIfError(t *testing.T, err error, format string, args ...interface{}) {
if err != nil {
t.Fatalf(format, args...)
}
}
func failIfOK(t *testing.T, err error, format string, args ...interface{}) {
if err == nil {
t.Fatalf(format, args...)
}
}
func createConnection(t *testing.T) *sql.DB {
connection, err := sql.Open("sqlite3", ":memory:")
failIfError(t, err, "unable to create fixture DB: %s", err)
return connection
}
func createProviderFromConnection(t *testing.T, connection *sql.DB) (p Provider) {
var err error
if p, err = FromDbConnection(connection); err != nil {
t.Errorf("failed to create DB: %s", err)
}
return
}
func createProvider(t *testing.T) (p Provider) {
var err error
if p, err = FromSqlite(":memory:"); err != nil {
t.Errorf("failed to create DB: %s", err)
}
return
}