forked from abhishekkr/goshare
/
dbtasks_test.go
145 lines (117 loc) · 3.61 KB
/
dbtasks_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
package goshare
import (
"testing"
goltime "github.com/abhishekkr/gol/goltime"
abklevigoNS "github.com/abhishekkr/levigoNS"
abkleveldb "github.com/abhishekkr/levigoNS/leveldb"
)
var (
test_dbpath = "/tmp/delete-this-goshare"
)
func setupTestData() {
db = abkleveldb.CreateDB(test_dbpath)
abkleveldb.PushKeyVal("upstate:2014:January:2:12:1:20", "down", db)
abklevigoNS.PushNS("upstate:2014:January:2:12:1:20", "down", db)
abklevigoNS.PushNS("upstate:2014:January:2:12:11:20", "up", db)
}
func TestGetVal(t *testing.T) {
setupTestData()
expected_val := "down"
result_val := GetVal("upstate:2014:January:2:12:1:20")
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestPushKeyVal(t *testing.T) {
setupTestData()
expected_val := "yeah"
status := PushKeyVal("oh", expected_val)
result_val := abkleveldb.GetVal("oh", db)
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
if !status {
t.Error("Fail: Wrong status returned by PushKeyVal")
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestDelKey(t *testing.T) {
setupTestData()
status := DelKey("upstate:2014:January:2:12:1:20")
expected_val := ""
result_val := abkleveldb.GetVal("oh", db)
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
if !status {
t.Error("Fail: Wrong status returned by DelKey")
}
status = DelKey("oh")
if !status {
t.Error("Fail: Wrong status returned by DelKey")
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestGetValNS(t *testing.T) {
setupTestData()
expected_val := "upstate:2014:January:2:12:1:20,down\n"
expected_val += "upstate:2014:January:2:12:11:20,up\n"
result_val := GetValNS("upstate:2014:January")
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestPushKeyValNS(t *testing.T) {
setupTestData()
expected_val := "right"
status := PushKeyValNS("oh:yeah", expected_val)
result_val := abkleveldb.GetVal("val::oh:yeah", db)
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
if !status {
t.Error("Fail: Wrong status returned by PushKeyValNS")
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestDelKeyNS(t *testing.T) {
setupTestData()
status := DelKeyNS("upstate:2014")
expected_val := ""
result_val := abkleveldb.GetVal("val::upstate:2014:January:2:12:1:20", db)
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
if !status {
t.Error("Fail: Wrong status returned by DelKeyNS")
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestGetValTSDS(t *testing.T) {
setupTestData()
expected_val := "upstate:2014:January:2:12:1:20,down\n"
expected_val += "upstate:2014:January:2:12:11:20,up\n"
result_val := GetValTSDS("upstate:2014:January:2")
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
func TestPushKeyValTSDS(t *testing.T) {
setupTestData()
ohtime := goltime.Timestamp{
Year: 2014, Month: 1, Day: 2, Hour: 12, Min: 1, Sec: 20,
}
status := PushKeyValTSDS("oh", "yeah", ohtime)
expected_val := "yeah"
result_val := abkleveldb.GetVal("val::oh:2014:January:2:12:1:20", db)
if expected_val != result_val {
t.Error("Fail: Get", result_val, "instead of", expected_val)
}
if !status {
t.Error("Fail: Wrong status returned by PushKeyValTSDS")
}
abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}