forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_test.go
76 lines (68 loc) · 1.59 KB
/
scan_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
package dynamo
import (
"reflect"
"testing"
"time"
)
func TestScan(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
table := testDB.Table(testTable)
// first, add an item to make sure there is at least one
item := widget{
UserID: 42,
Time: time.Now().UTC(),
Msg: "hello",
}
err := table.Put(item).Run()
if err != nil {
t.Error("unexpected error:", err)
}
// now check if get all and count return the same amount of items
var result []widget
var cc ConsumedCapacity
err = table.Scan().Filter("UserID = ?", 42).Consistent(true).ConsumedCapacity(&cc).All(&result)
if err != nil {
t.Error("unexpected error:", err)
}
ct, err := table.Get("UserID", 42).Consistent(true).Count()
if err != nil {
t.Error("unexpected error:", err)
}
if int(ct) != len(result) {
t.Errorf("count and scan don't match. count: %d, scan: %d", ct, len(result))
}
if cc.Total == 0 {
t.Error("bad consumed capacity", cc)
}
// search for our inserted item
found := false
for _, w := range result {
if w.Time.Equal(item.Time) && reflect.DeepEqual(w, item) {
found = true
break
}
}
if !found {
t.Error("exact match of put item not found in scan")
}
}
func TestScanPaging(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
table := testDB.Table(testTable)
widgets := [10]widget{}
itr := table.Scan().SearchLimit(1).Iter()
for i := 0; i < len(widgets); i++ {
more := itr.Next(&widgets[i])
if itr.Err() != nil {
t.Error("unexpected error", itr.Err())
}
if !more {
break
}
itr = table.Scan().StartFrom(itr.LastEvaluatedKey()).SearchLimit(1).Iter()
}
}