This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
unqlite_test.go
162 lines (154 loc) · 4.12 KB
/
unqlite_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package unqlitego
import (
"bytes"
"fmt"
. "github.com/r7kamura/gospel"
"io/ioutil"
"testing"
)
func Testライブラリ(t *testing.T) {
Describe(t, "正常系", func() {
Context("基本テスト", func() {
It("IsThreadSafe", func() {
Expect(IsThreadSafe()).To(Equal, true)
})
It("Version", func() {
Expect(Version()).To(Equal, "1.1.6")
})
It("Signature", func() {
Expect(Signature()).To(Equal, "unqlite/1.1.6")
})
It("Ident", func() {
Expect(Ident()).To(Equal, "unqlite:b172a1e2c3f62fb35c8e1fb2795121f82356cad6")
})
It("Copyright", func() {
Expect(Copyright()).To(Equal, "Copyright (C) Symisc Systems, S.U.A.R.L [Mrad Chems Eddine <[email protected]>] 2012-2013, http://unqlite.org/")
})
})
})
}
func Testモジュール(t *testing.T) {
var db *Database
var src []byte
src = []byte("value")
Describe(t, "正常系", func() {
Context("基本テスト", func() {
It("NewDatabase", func() {
f, err := ioutil.TempFile("", "sample.db")
if err != nil {
panic(err)
}
db, err = NewDatabase(f.Name())
Expect(err).To(NotExist)
Expect(db).To(Exist)
})
It("Database.Begin", func() {
err := db.Begin()
Expect(err).To(NotExist)
})
It("Database.Store", func() {
err := db.Store([]byte("sample"), src)
Expect(err).To(NotExist)
})
It("Database.Store.ZeroByte", func() {
err := db.Store([]byte{}, src)
Expect(err).To(Exist)
})
It("Database.Fetch", func() {
dst, err := db.Fetch([]byte("sample"))
Expect(err).To(NotExist)
Expect(bytes.Compare(src, dst)).To(Equal, 0)
})
It("Database.Fetch.ZeroByte", func() {
value, err := db.Fetch([]byte{})
Expect(err).To(Exist)
Expect(value).To(NotExist)
})
It("Database.Append", func() {
err1 := db.Append([]byte("sample"), []byte(" append"))
Expect(err1).To(NotExist)
dst, err2 := db.Fetch([]byte("sample"))
Expect(err2).To(NotExist)
Expect(bytes.Compare(append(src, []byte(" append")...), dst)).To(Equal, 0)
})
It("Database.Commit", func() {
err := db.Commit()
Expect(err).To(NotExist)
})
It("Database.Begin", func() {
err := db.Begin()
Expect(err).To(NotExist)
})
It("Database.Delete", func() {
err1 := db.Delete([]byte("sample"))
Expect(err1).To(NotExist)
_, err2 := db.Fetch([]byte("sample"))
Expect(err2).To(Exist)
})
It("Database.Rollback", func() {
err := db.Rollback()
Expect(err).To(NotExist)
value, err2 := db.Fetch([]byte("sample"))
Expect(err2).To(NotExist)
Expect(value).To(Exist)
})
It("Database.NewCursor", func() {
cursor, err := db.NewCursor()
Expect(err).To(NotExist)
Expect(cursor).To(Exist)
err = cursor.Seek([]byte("sample"))
Expect(err).To(NotExist)
})
It("Database.Close", func() {
err := db.Close()
Expect(err).To(NotExist)
})
})
})
}
func BenchmarkFileStore(b *testing.B) {
b.StopTimer()
f, err := ioutil.TempFile("", "sample.db")
if err != nil {
panic(err)
}
db, _ := NewDatabase(f.Name())
b.StartTimer()
for i := 0; i < b.N; i++ {
db.Store([]byte(fmt.Sprintf("%d", i)), []byte("abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop"))
}
}
func BenchmarkFileFetch(b *testing.B) {
b.StopTimer()
f, err := ioutil.TempFile("", "sample.db")
if err != nil {
panic(err)
}
db, _ := NewDatabase(f.Name())
for i := 0; i < b.N; i++ {
db.Store([]byte(fmt.Sprintf("%d", i)), []byte("abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop"))
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _ = db.Fetch([]byte(fmt.Sprintf("%d", i)))
}
}
func BenchmarkMemStore(b *testing.B) {
b.StopTimer()
db, _ := NewDatabase("")
b.StartTimer()
for i := 0; i < b.N; i++ {
db.Store([]byte(fmt.Sprintf("%d", i)), []byte("abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop"))
}
}
func BenchmarkMemFetch(b *testing.B) {
b.StopTimer()
db, _ := NewDatabase("")
for i := 0; i < b.N; i++ {
db.Store([]byte(fmt.Sprintf("%d", i)), []byte("abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop"))
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _ = db.Fetch([]byte(fmt.Sprintf("%d", i)))
}
}