-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite_test.go
129 lines (105 loc) · 2.58 KB
/
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package sqldb
import (
"net/url"
"strings"
"testing"
)
func TestNewSQLite(t *testing.T) {
c := NewSQLite("/path/to/sqlite.db")
if c.Type != DBTypeSQLite {
t.FailNow()
return
}
}
func TestIsSQLite(t *testing.T) {
c := NewSQLite("/path/to/sqlite.db")
if !c.IsSQLite() {
t.Fatal("DB type isn't detected as SQLite", c.Type)
return
}
}
func TestGetSQLiteVersion(t *testing.T) {
v, err := GetSQLiteVersion()
if err != nil {
t.Fatal(err)
return
}
if v == "" {
t.Fatal("SQLite version not returned.", v)
return
}
}
func TestPragmasToURLValues(t *testing.T) {
//Test with mattn, single PRAGMA.
t.Run("mattn", func(t *testing.T) {
lib := sqliteLibraryMattn
pragmas := []string{
"PRAGMA busy_timeout = 5000",
}
got := pragmasToURLValues(pragmas, lib)
expected := url.Values{}
expected.Add("_busy_timeout", "5000")
if got.Encode() != expected.Encode() {
t.Log("Got:", got)
t.Log("Exp:", expected)
t.Fatal("mismatch for mattn library")
}
})
//Test with mattn, multiple PRAGMAs.
t.Run("mattn-multi", func(t *testing.T) {
lib := sqliteLibraryMattn
pragmas := []string{
"PRAGMA busy_timeout = 5000",
"PRAGMA journal_mode = WAL",
}
got := pragmasToURLValues(pragmas, lib)
expected := url.Values{}
expected.Add("_busy_timeout", "5000")
expected.Add("_journal_mode", "wal")
if got.Encode() != expected.Encode() {
t.Log("Got:", got)
t.Log("Exp:", expected)
t.Fatal("mismatch for mattn library")
return
}
})
//Test with modernc, single PRAGMA
t.Run("modernc", func(t *testing.T) {
lib := sqliteLibraryModernc
pragmas := []string{
"PRAGMA busy_timeout = 5000",
}
got := pragmasToURLValues(pragmas, lib)
expected := url.Values{}
expected.Add("_pragma", "busy_timeout=5000")
if got.Encode() != expected.Encode() {
t.Log("Got:", got)
t.Log("Exp:", expected)
t.Fatal("mismatch for modernc library")
}
})
//Test with modernc, multiple PRAGMAs.
t.Run("modernc-multi", func(t *testing.T) {
lib := sqliteLibraryModernc
pragmas := []string{
"PRAGMA busy_timeout = 5000",
"PRAGMA journal_mode = WAL",
}
got := pragmasToURLValues(pragmas, lib)
expected := url.Values{}
expected.Add("_pragma", "busy_timeout=5000")
expected.Add("_pragma", "journal_mode=wal")
if got.Encode() != expected.Encode() {
t.Log("Got:", got)
t.Log("Exp:", expected)
t.Fatal("mismatch for modernc library")
return
}
if strings.Count(got.Encode(), "_pragma") != len(pragmas) {
t.Log("Got:", got.Encode())
t.Log("Exp:", expected.Encode())
t.Fatal("mismatch for modernc library")
return
}
})
}