-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite_test.go
87 lines (68 loc) · 1.77 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
package dotlite
import (
"testing"
)
func open(t *testing.T, name string) *File {
var file, err = Open(name)
if err != nil {
t.Errorf("failed to open file: %v", err)
}
return file
}
func TestOpen(t *testing.T) {
var file = open(t, "testdata/chinook.db")
defer file.Close()
if sz := file.PageSize(); sz != 1024 {
t.Errorf("expected page size to be %d; got %d", 1024, sz)
}
if ver := file.Version(); ver != 3041000 {
t.Errorf("expected library version to be %d; got %d", 3041000, ver)
}
if enc := file.Encoding(); enc != UTF8 {
t.Errorf("expected encoding to be %d; got %d", UTF8, enc)
}
}
func TestOpen_invalid_magic(t *testing.T) {
if _, err := Open("testdata/not-a-database.txt"); err == nil {
t.Errorf("expected invalid magic error")
}
}
func TestOpen_size_is_computed(t *testing.T) {
// 4 bytes starting at position 28 are zeroed
var file = open(t, "testdata/chinook-no-size.db")
defer file.Close()
if sz := file.NumPages(); sz != 1042 {
t.Errorf("expected page count to be %d; got %d", 1042, sz)
}
}
func TestSchema(t *testing.T) {
var file = open(t, "testdata/chinook.db")
defer file.Close()
objects, err := file.Schema()
if err != nil {
t.Errorf("failed to determine schema: %v", err)
}
if tl := len(objects); tl != 23 {
t.Errorf("expected %d objects; got %d", 23, tl)
}
}
func TestSchema_find_table(t *testing.T) {
var file = open(t, "testdata/chinook.db")
defer file.Close()
if _, err := file.Object("Album"); err != nil {
t.Error(err)
}
if table, err := file.Object("NotExist"); err == nil || table != nil {
t.Fail()
}
}
func TestOverflow_database(t *testing.T) {
var file = open(t, "testdata/overflow.db")
defer file.Close()
var err = file.ForEach("x", func(_ *Record) error {
return nil
})
if err != nil {
t.Error(err)
}
}