-
Notifications
You must be signed in to change notification settings - Fork 5
/
database_test.go
73 lines (53 loc) · 1.39 KB
/
database_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
package sisyphus_test
import (
"os"
"github.com/boltdb/bolt"
. "github.com/carlostrub/sisyphus"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Database", func() {
Context("Bolt Database", func() {
AfterEach(func() {
err = os.Remove("test/Maildir/sisyphus.db")
Ω(err).ShouldNot(HaveOccurred())
})
It("Load databases for each maildir", func() {
dbs, err := LoadDatabases([]Maildir{"test/Maildir"})
Ω(err).ShouldNot(HaveOccurred())
dbTest := dbs["test/Maildir"]
var gN = 4
var jN = 4
var sN = 4
err = dbTest.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("Wordlists"))
good := b.Bucket([]byte("Good"))
gN = good.Stats().KeyN
junk := b.Bucket([]byte("Junk"))
jN = junk.Stats().KeyN
s := tx.Bucket([]byte("Statistics"))
sN = s.Stats().KeyN
return nil
})
Ω(err).ShouldNot(HaveOccurred())
Ω(gN).Should(Equal(0))
Ω(jN).Should(Equal(0))
Ω(sN).Should(Equal(0))
CloseDatabases(dbs)
})
It("Closes an open database", func() {
dbs, err := LoadDatabases([]Maildir{"test/Maildir"})
Ω(err).ShouldNot(HaveOccurred())
CloseDatabases(dbs)
dbTest := dbs["test/Maildir"]
n := 4
err = dbTest.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("Statistics"))
n = b.Stats().KeyN
return nil
})
Ω(err).Should(HaveOccurred())
Ω(n).Should(Equal(4))
})
})
})