-
Notifications
You must be signed in to change notification settings - Fork 8
/
delete_test.go
99 lines (79 loc) · 1.85 KB
/
delete_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
package sortedmap
import (
"testing"
"time"
)
func TestDelete(t *testing.T) {
const shouldFailErr = "Equal bound values that do not match a stored value should always fail."
sm, records, err := newSortedMapFromRandRecords(300)
if err != nil {
t.Fatal(err)
}
if sm.Delete("") {
t.Fatalf("Delete: %v", invalidDelete)
}
for _, rec := range records {
sm.Delete(rec.Key)
}
_, err = sm.IterCh()
if err == nil {
t.Fatal(shouldFailErr)
}
}
func TestBatchDelete(t *testing.T) {
sm, records, err := newSortedMapFromRandRecords(300)
if err != nil {
t.Fatal(err)
}
keys := make([]interface{}, 0)
for i, rec := range records {
if i == 50 {
break
}
keys = append(keys, rec.Key)
}
for _, ok := range sm.BatchDelete(keys) {
if !ok {
t.Fatalf("BatchDelete: %v", invalidDelete)
}
}
iterCh, err := sm.IterCh()
if err != nil {
t.Fatal(err)
} else {
defer iterCh.Close()
if err := verifyRecords(iterCh.Records(), false); err != nil {
t.Fatal(err)
}
}
}
func TestBoundedDelete(t *testing.T) {
const (
nilBoundValsErr = "accepted nil bound value"
generalBoundsErr = "general bounds error"
shouldFailErr = "Equal bound values that do not match a stored value should always fail."
)
sm, _, err := newSortedMapFromRandRecords(300)
if err != nil {
t.Fatal(err)
}
earlierDate := time.Date(200, 1, 1, 0, 0, 0, 0, time.UTC)
if err := sm.BoundedDelete(nil, nil); err != nil {
t.Fatal(err)
}
if err := sm.BoundedDelete(nil, time.Now()); err != nil {
t.Fatal(err)
}
if err := sm.BoundedDelete(time.Now(), nil); err != nil {
t.Fatal(err)
}
if err := sm.BoundedDelete(earlierDate, time.Now()); err != nil {
t.Fatal(err)
}
if err := sm.BoundedDelete(time.Now(), earlierDate); err == nil {
t.Fatal(shouldFailErr)
}
if err := sm.BoundedDelete(earlierDate, earlierDate); err == nil {
t.Fatal(shouldFailErr)
}
}