forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_test.go
62 lines (53 loc) · 1.34 KB
/
decode_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
package dynamo
import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
func TestUnmarshalAppend(t *testing.T) {
var results []struct {
User int `dynamo:"UserID"`
Page int
}
id := "12345"
page := "5"
item := map[string]*dynamodb.AttributeValue{
"UserID": &dynamodb.AttributeValue{N: &id},
"Page": &dynamodb.AttributeValue{N: &page},
}
for range [15]struct{}{} {
err := unmarshalAppend(item, &results)
if err != nil {
t.Fatal(err)
}
}
for _, h := range results {
if h.User != 12345 || h.Page != 5 {
t.Error("invalid hit", h)
}
}
}
func TestUnmarshal(t *testing.T) {
for _, tc := range encodingTests {
rv := reflect.New(reflect.TypeOf(tc.in))
err := unmarshalReflect(tc.out, rv.Elem())
if err != nil {
t.Errorf("%s: unexpected error: %v", tc.name, err)
}
if !reflect.DeepEqual(rv.Elem().Interface(), tc.in) {
t.Errorf("%s: bad result: %#v ≠ %#v", tc.name, rv.Elem().Interface(), tc.out)
}
}
}
func TestUnmarshalItem(t *testing.T) {
for _, tc := range itemEncodingTests {
rv := reflect.New(reflect.TypeOf(tc.in))
err := unmarshalItem(tc.out, rv.Interface())
if err != nil {
t.Errorf("%s: unexpected error: %v", tc.name, err)
}
if !reflect.DeepEqual(rv.Elem().Interface(), tc.in) {
t.Errorf("%s: bad result: %#v ≠ %#v", tc.name, rv.Elem().Interface(), tc.in)
}
}
}