-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathquery_result_test.go
60 lines (45 loc) · 1.17 KB
/
query_result_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
package dynamodb
import (
"testing"
"github.com/stretchr/testify/assert"
)
func getTestQueryResult(t *testing.T) *QueryResult {
setupQueryTable(t)
tbl := getTestTable(t)
c := tbl.NewConditionList()
c.AndEQ("id", 5)
c.AndLE("time", 2)
result, _ := tbl.Query(c)
return result
}
func TestToSliceMap(t *testing.T) {
assert := assert.New(t)
r := getTestQueryResult(t)
list := r.ToSliceMap()
assert.Len(list, 2)
assert.Equal(5, list[0]["id"])
assert.Equal(1, list[0]["time"])
assert.Equal("lsi_value", list[0]["lsi_key"])
assert.Equal(5, list[1]["id"])
assert.Equal(2, list[1]["time"])
assert.Equal("lsi_value", list[1]["lsi_key"])
}
func TestUnmarshal(t *testing.T) {
assert := assert.New(t)
type myStruct struct {
ID int64
UnixTime int64 `dynamodb:"time"`
LSIKey string `dynamodb:"lsi_key"`
}
r := getTestQueryResult(t)
var list []*myStruct
err := r.Unmarshal(&list)
assert.NoError(err)
assert.Len(list, 2)
assert.EqualValues(5, list[0].ID)
assert.EqualValues(1, list[0].UnixTime)
assert.Equal("lsi_value", list[0].LSIKey)
assert.EqualValues(5, list[1].ID)
assert.EqualValues(2, list[1].UnixTime)
assert.Equal("lsi_value", list[1].LSIKey)
}