-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel_test.go
128 lines (124 loc) · 2.29 KB
/
model_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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package csv2dynamo
import (
"github.com/google/go-cmp/cmp"
"reflect"
"testing"
)
func TestCopy(t *testing.T) {
d := DynamoInput{
DynamoData{
Key: "SKey",
Type: "S",
Val: "",
},
}
cp := d.Copy()
if diff := cmp.Diff(d, cp); diff != "" {
t.Fatalf("copied obj mismatch (-data +copy):\n%s", diff)
}
if reflect.ValueOf(d).Pointer() == reflect.ValueOf(cp).Pointer() {
t.Fatalf("Copy is not shallow copy")
}
}
func Test_DynamoInput_ToJsonString(t *testing.T) {
tests := []struct {
name string
in DynamoInput
execute bool
want string
}{
{
name: `single value "S"`,
in: DynamoInput{
DynamoData{
Key: `key_S"`,
Type: `"S"`,
Val: "val_S",
},
},
execute: false,
want: `'{"key_S":{"S":"val_S"}}'`,
},
{
name: `single value "N"`,
in: DynamoInput{
DynamoData{
Key: `key_N"`,
Type: `"N"`,
Val: "1",
},
},
execute: false,
want: `'{"key_N":{"N":"1"}}'`,
},
{
name: `single value "BOOL"`,
in: DynamoInput{
DynamoData{
Key: `key_BOOL"`,
Type: `"BOOL"`,
Val: "true",
},
},
execute: false,
want: `'{"key_BOOL":{"BOOL":true}}'`,
},
{
name: `multiple value`,
in: DynamoInput{
DynamoData{
Key: `key_S"`,
Type: `"S"`,
Val: "val_S",
},
DynamoData{
Key: `key_N"`,
Type: `"N"`,
Val: "1",
},
DynamoData{
Key: `key_BOOL"`,
Type: `"BOOL"`,
Val: "true",
},
DynamoData{
Key: `empty"`,
Type: `"S"`,
Val: "",
},
},
execute: false,
want: `'{"key_S":{"S":"val_S"},"key_N":{"N":"1"},"key_BOOL":{"BOOL":true}}'`,
},
{
name: `output for dirext execute`,
in: DynamoInput{
DynamoData{
Key: `key_S"`,
Type: `"S"`,
Val: "val_S",
},
DynamoData{
Key: `key_N"`,
Type: `"N"`,
Val: "1",
},
DynamoData{
Key: `key_BOOL"`,
Type: `"BOOL"`,
Val: "true",
},
},
execute: true,
want: `{"key_S":{"S":"val_S"},"key_N":{"N":"1"},"key_BOOL":{"BOOL":true}}`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.in.ToJsonString(tt.execute)
if diff := cmp.Diff(got, tt.want); diff != "" {
t.Errorf("json string mismatch (-got +want):\n%s", diff)
}
})
}
}