-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitcask_test.go
36 lines (31 loc) · 1.02 KB
/
bitcask_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
package golkeyval
import (
"os"
"testing"
"github.com/gol-gol/golassert"
)
func TestBitcaskInit(t *testing.T) {
golassert.Type(t, DBEngines["bitcask"], new(Bitcask))
}
func TestBitcaskConfigureCreateAndCloseDB(t *testing.T) {
kv := new(Bitcask)
kv.Configure(map[string]string{"DBPath": "/tmp/test-db-bitcask"})
kv.CreateDB()
kv.CloseDB()
if os.RemoveAll(kv.DBPath) != nil {
panic("Fail: Temporary DB files are still present at: " + kv.DBPath)
}
}
func TestBitcaskPushGetDelDB(t *testing.T) {
kv := new(Bitcask)
kv.Configure(map[string]string{"DBPath": "/tmp/test-db-leveldb"})
kv.CreateDB()
golassert.Equal(t, "", kv.GetVal("sample-key"))
golassert.Equal(t, true, kv.PushKeyVal("sample-key", "sample-value"))
golassert.Equal(t, "sample-value", kv.GetVal("sample-key"))
golassert.Equal(t, true, kv.PushKeyVal("sample-key", "next-value"))
golassert.Equal(t, "next-value", kv.GetVal("sample-key"))
golassert.Equal(t, true, kv.DelKey("sample-key"))
golassert.Equal(t, "", kv.GetVal("sample-key"))
kv.CloseAndDeleteDB()
}