forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialect_sqlite_test.go
111 lines (98 loc) · 3.09 KB
/
dialect_sqlite_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
105
106
107
108
109
110
111
// +build sqlite
package pop
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func Test_ConnectionDetails_Finalize_SQLite_URL_Only(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
URL: "sqlite3:///tmp/foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: N/A")
r.Equal("/tmp/foo.db", cd.Database, "given url: sqlite3:///tmp/foo.db")
}
func Test_ConnectionDetails_Finalize_SQLite_SynURL_Only(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
URL: "sqlite:///tmp/foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: N/A")
r.Equal("/tmp/foo.db", cd.Database, "given url: sqlite:///tmp/foo.db")
}
func Test_ConnectionDetails_Finalize_SQLite_Dialect_URL(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "sqlite3",
URL: "sqlite3:///tmp/foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: sqlite3")
r.Equal("/tmp/foo.db", cd.Database, "given url: sqlite3:///tmp/foo.db")
}
func Test_ConnectionDetails_Finalize_SQLite_Dialect_SynURL(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "sqlite3",
URL: "sqlite:///tmp/foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: sqlite3")
r.Equal("/tmp/foo.db", cd.Database, "given url: sqlite:///tmp/foo.db")
}
func Test_ConnectionDetails_Finalize_SQLite_Synonym_URL(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "sqlite",
URL: "sqlite3:///tmp/foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: sqlite")
r.Equal("/tmp/foo.db", cd.Database, "given url: sqlite3:///tmp/foo.db")
}
func Test_ConnectionDetails_Finalize_SQLite_Synonym_SynURL(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "sqlite",
URL: "sqlite:///tmp/foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: sqlite")
r.Equal("/tmp/foo.db", cd.Database, "given url: sqlite:///tmp/foo.db")
}
func Test_ConnectionDetails_Finalize_SQLite_Synonym_Path(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "sqlite",
Database: "./foo.db",
}
err := cd.Finalize() // calls withURL() and urlParserSQLite3(cd)
r.NoError(err)
r.Equal("sqlite3", cd.Dialect, "given dialect: sqlite")
r.Equal("./foo.db", cd.Database, "given database: ./foo.db")
}
func Test_ConnectionDetails_FinalizeOSPath(t *testing.T) {
r := require.New(t)
d, err := ioutil.TempDir("", "")
r.NoError(err)
p := filepath.Join(d, "testdb.sqlite")
defer os.RemoveAll(p)
cd := &ConnectionDetails{
Dialect: "sqlite",
Database: p,
}
r.NoError(cd.Finalize())
r.Equal("sqlite3", cd.Dialect)
r.Equal(p, cd.Database)
}