-
Notifications
You must be signed in to change notification settings - Fork 27
/
mysql_test.go
104 lines (86 loc) · 2.22 KB
/
mysql_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package godb_test
import (
"os"
"testing"
"github.com/samonzeweb/godb"
"github.com/samonzeweb/godb/adapters/mysql"
"github.com/samonzeweb/godb/dbtests/common"
. "github.com/smartystreets/goconvey/convey"
)
func fixturesSetupMySQL(t *testing.T) (*godb.DB, func()) {
if os.Getenv("GODB_MYSQL") == "" {
t.Skip("Don't run MySQL test, GODB_MYSQL not set")
}
db, err := godb.Open(mysql.Adapter, os.Getenv("GODB_MYSQL"))
if err != nil {
t.Fatal(err)
}
// Enable logger if needed
//db.SetLogger(log.New(os.Stderr, "", 0))
createTable :=
`create table if not exists books (
id int auto_increment primary key,
title varchar(128) not null,
author varchar(128) not null,
published date not null,
version int not null default 0);
`
_, err = db.CurrentDB().Exec(createTable)
if err != nil {
t.Fatal(err)
}
createTable = `create table if not exists inventories (
id int auto_increment primary key,
book_id int not null,
last_inventory date not null,
counting int not null default 0);
`
_, err = db.CurrentDB().Exec(createTable)
if err != nil {
t.Fatal(err)
}
fixturesTeardown := func() {
dropTable := "drop table if exists books;"
_, err := db.CurrentDB().Exec(dropTable)
if err != nil {
t.Fatal(err)
}
dropTable = "drop table if exists inventories;"
_, err = db.CurrentDB().Exec(dropTable)
if err != nil {
t.Fatal(err)
}
err = db.Close()
if err != nil {
t.Fatal(err)
}
}
return db, fixturesTeardown
}
func TestStatementsMySQL(t *testing.T) {
Convey("A DB for a MySQL database", t, func() {
db, teardown := fixturesSetupMySQL(t)
defer teardown()
Convey("The common statements tests must pass", func() {
common.StatementsTests(db, t)
})
})
}
func TestStructsMySQL(t *testing.T) {
Convey("A DB for a MySQL database", t, func() {
db, teardown := fixturesSetupMySQL(t)
defer teardown()
Convey("The common structs tests must pass", func() {
common.StructsTests(db, t)
})
})
}
func TestRawMySQL(t *testing.T) {
Convey("A DB for a SQLite database", t, func() {
db, teardown := fixturesSetupMySQL(t)
defer teardown()
Convey("The common raw tests must pass", func() {
common.RawSQLTests(db, t)
})
})
}