2
0
mirror of https://github.com/carlostrub/sisyphus synced 2024-10-31 09:20:15 +00:00
sisyphus/database_test.go

74 lines
1.4 KiB
Go
Raw Permalink Normal View History

2017-05-10 19:09:02 +00:00
package sisyphus_test
import (
2017-05-11 18:20:36 +00:00
"os"
2017-05-10 19:09:02 +00:00
"github.com/boltdb/bolt"
. "github.com/carlostrub/sisyphus"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Database", func() {
Context("Bolt Database", func() {
2017-05-11 19:15:36 +00:00
AfterEach(func() {
err = os.Remove("test/Maildir/sisyphus.db")
Ω(err).ShouldNot(HaveOccurred())
})
2017-05-10 19:09:02 +00:00
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))
2017-05-11 02:47:00 +00:00
CloseDatabases(dbs)
})
It("Closes an open database", func() {
dbs, err := LoadDatabases([]Maildir{"test/Maildir"})
Ω(err).ShouldNot(HaveOccurred())
CloseDatabases(dbs)
dbTest := dbs["test/Maildir"]
2017-05-13 22:34:54 +00:00
n := 4
2017-05-11 02:47:00 +00:00
err = dbTest.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("Statistics"))
n = b.Stats().KeyN
return nil
})
Ω(err).Should(HaveOccurred())
2017-05-13 22:34:54 +00:00
Ω(n).Should(Equal(4))
2017-05-10 19:09:02 +00:00
})
})
})