forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_test.go
52 lines (46 loc) · 1.06 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
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
err = table.Scan().Filter("UserID = ?", 42).Consistent(true).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))
}
// 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")
}
}