-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite3_test.go
39 lines (34 loc) · 1.07 KB
/
sqlite3_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
package golkeyval
import (
"os"
"testing"
"github.com/gol-gol/golassert"
)
func TestSqlite3DBInit(t *testing.T) {
golassert.Type(t, DBEngines["sqlite3"], new(Sqlite3DB))
}
func TestSqlite3DBConfigureCreateAndCloseDB(t *testing.T) {
kv := new(Sqlite3DB)
kv.Configure(map[string]string{
"DBPath": "/tmp/test-db-sqlite3",
"TableName": "testkv",
})
kv.CreateDB()
kv.CloseDB()
if os.RemoveAll(kv.DBPath) != nil {
panic("Fail: Temporary DB files are still present at: " + kv.DBPath)
}
}
func TestSqlite3DBPushGetDelDB(t *testing.T) {
kv := new(Sqlite3DB)
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()
}