forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_test.go
More file actions
104 lines (95 loc) · 2.42 KB
/
Copy pathencode_test.go
File metadata and controls
104 lines (95 loc) · 2.42 KB
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
100
101
102
103
104
package dynamo
import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
var itemEncodeOnlyTests = []struct {
name string
in interface{}
out map[string]*dynamodb.AttributeValue
}{
{
name: "omitemptyelem",
in: struct {
L []*string `dynamo:",omitemptyelem"`
SS []string `dynamo:",omitemptyelem,set"`
M map[string]string `dynamo:",omitemptyelem"`
Other bool
}{
L: []*string{nil, aws.String("")},
SS: []string{""},
M: map[string]string{"test": ""},
Other: true,
},
out: map[string]*dynamodb.AttributeValue{
"L": &dynamodb.AttributeValue{L: []*dynamodb.AttributeValue{}},
"M": &dynamodb.AttributeValue{M: map[string]*dynamodb.AttributeValue{}},
"Other": &dynamodb.AttributeValue{BOOL: aws.Bool(true)},
},
},
{
name: "omitemptyelem + omitempty",
in: struct {
L []*string `dynamo:",omitemptyelem,omitempty"`
M map[string]string `dynamo:",omitemptyelem,omitempty"`
Other bool
}{
L: []*string{nil, aws.String("")},
M: map[string]string{"test": ""},
Other: true,
},
out: map[string]*dynamodb.AttributeValue{
"Other": &dynamodb.AttributeValue{BOOL: aws.Bool(true)},
},
},
{
name: "unexported field",
in: struct {
Public int
private int
private2 *int
}{
Public: 555,
private: 1337,
private2: new(int),
},
out: map[string]*dynamodb.AttributeValue{
"Public": &dynamodb.AttributeValue{N: aws.String("555")},
},
},
}
func TestMarshal(t *testing.T) {
for _, tc := range encodingTests {
item, err := marshal(tc.in, flagNone)
if err != nil {
t.Errorf("%s: unexpected error: %v", tc.name, err)
}
if !reflect.DeepEqual(item, tc.out) {
t.Errorf("%s: bad result: %#v ≠ %#v", tc.name, item, tc.out)
}
}
}
func TestMarshalItem(t *testing.T) {
for _, tc := range itemEncodingTests {
item, err := marshalItem(tc.in)
if err != nil {
t.Errorf("%s: unexpected error: %v", tc.name, err)
}
if !reflect.DeepEqual(item, tc.out) {
t.Errorf("%s: bad result: %#v ≠ %#v", tc.name, item, tc.out)
}
}
}
func TestMarshalItemAsymmetric(t *testing.T) {
for _, tc := range itemEncodeOnlyTests {
item, err := marshalItem(tc.in)
if err != nil {
t.Errorf("%s: unexpected error: %v", tc.name, err)
}
if !reflect.DeepEqual(item, tc.out) {
t.Errorf("%s: bad result: %#v ≠ %#v", tc.name, item, tc.out)
}
}
}