-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsnapshot_test.go
118 lines (100 loc) · 2.21 KB
/
snapshot_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
package snapshot
import (
"testing"
"time"
)
type user struct {
Name, Email string
Phone int
CreatedAt time.Time
}
var userCollection *Collection
func TestMain(m *testing.M) {
userCollection, _ = New("users")
m.Run()
}
func TestCollection_Put(t *testing.T) {
john := user{"John Doe", "[email protected]", 9898787, time.Now()}
err := userCollection.Put("john", &john)
if err != nil {
t.Error("Failed to Put in collection!")
}
}
func TestCollection_Get(t *testing.T) {
john := user{}
err := userCollection.Get("john", &john)
if err != nil {
t.Error("Failed to Get from collection!")
}
if john.Name != "John Doe" {
t.Error("Failed to Get correct data")
}
}
func TestCollection_Has(t *testing.T) {
if !userCollection.Has("john") {
t.Error("Failed to check using Has method!")
}
}
func TestCollection_List(t *testing.T) {
list, err := userCollection.List()
if err != nil {
t.Error(err)
}
if len(list) != 1 {
t.Error("Failed to get collection keys list!")
}
}
func TestCollection_TotalItem(t *testing.T) {
if userCollection.TotalItem() != 1 {
t.Error("Failed to count total item number!")
}
}
func TestCollection_Remove(t *testing.T) {
err := userCollection.Remove("john")
if err != nil {
t.Error("Failed to remove from collection!")
}
}
func TestCollection_Flush(t *testing.T) {
err := userCollection.Flush()
if err != nil {
t.Error(err)
}
}
func BenchmarkCollection_Put(b *testing.B) {
john := user{"John Doe", "[email protected]", 9898787, time.Now()}
for n := 0; n < b.N; n++ {
userCollection.Put("john", &john)
}
}
func BenchmarkCollection_Get(b *testing.B) {
john := user{}
for n := 0; n < b.N; n++ {
userCollection.Get("john", &john)
}
}
func BenchmarkCollection_Has(b *testing.B) {
for n := 0; n < b.N; n++ {
userCollection.Has("john")
}
}
func BenchmarkCollection_List(b *testing.B) {
for n := 0; n < b.N; n++ {
userCollection.List()
}
}
func BenchmarkCollection_TotalItem(b *testing.B) {
for n := 0; n < b.N; n++ {
userCollection.TotalItem()
}
}
func BenchmarkCollection_Remove(b *testing.B) {
for n := 0; n < b.N; n++ {
userCollection.Remove("john")
}
}
func BenchmarkCollection_Flush(b *testing.B) {
for n := 0; n < b.N; n++ {
userCollection.Flush()
}
}