-
Notifications
You must be signed in to change notification settings - Fork 1
/
record_test.go
290 lines (258 loc) · 7.08 KB
/
record_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package filemaker
import (
"testing"
"time"
)
func newTestRecord() Record {
return newRecord(
"layout",
map[string]interface{}{
"recordId": "recordId",
"fieldData": map[string]interface{}{
"string": "string",
"int": float64(100),
"int8": float64(8),
"int16": float64(16),
"int32": float64(32),
"int64": float64(64),
"float32": float64(32.32),
"float64": float64(64.64),
"bool_true_txt_test": "test",
"bool_true_txt_false": "false",
"bool_false_txt": "",
"bool_true_num_1": float64(1),
"bool_true_num_123": float64(123),
"bool_false_num_0": float64(0),
"date_1": "01/02/2006",
"date_2": "2006-01-02",
"timestamp_1": "01/02/2006 15:04:05",
"timestamp_2": "2006-01-02 15:04:05",
"time_invalid": "january 1 2006 15 pm",
},
},
Session{
Token: "token",
Host: "host",
Database: "database",
Username: "username",
Password: "password",
},
)
}
type nestedStructPointer struct {
String string `fm:"string"`
}
type testRecordStruct struct {
String string `fm:"string"`
Int int `fm:"int"`
Int8 int8 `fm:"int8"`
Int16 int16 `fm:"int16"`
Int32 int32 `fm:"int32"`
Int64 int64 `fm:"int64"`
Float32 float32 `fm:"float32"`
Float64 float64 `fm:"float64"`
BoolTrueTxtTest bool `fm:"bool_true_txt_test"`
BoolTrueTxtFalse bool `fm:"bool_true_txt_false"`
BoolFalseTxt bool `fm:"bool_false_txt"`
BoolTrueNum1 bool `fm:"bool_true_num_1"`
BoolTrueNum123 bool `fm:"bool_true_num_123"`
BoolFalseNum0 bool `fm:"bool_false_num_0"`
Date1 time.Time `fm:"date_1"`
Date2 time.Time `fm:"date_2"`
Timestamp1 time.Time `fm:"timestamp_1"`
Timestamp2 time.Time `fm:"timestamp_2"`
TimeInvalid time.Time `fm:"time_invalid"`
TimePointer *time.Time `fm:"timestamp_1"`
TimePointerInvalid *time.Time `fm:"time_invalid"`
Nested struct {
String string `fm:"string"`
Nested struct {
String string `fm:"string"`
}
}
NestedStructPointer *nestedStructPointer
NestedNilStructPointer *nestedStructPointer
}
// TestRecordMap tests the `Record.Map` method
func TestRecordMap(t *testing.T) {
//Create a dummy record
record := newTestRecord()
//Create a struct to map the dummy record to
var value testRecordStruct
value.NestedStructPointer = &nestedStructPointer{}
//Map the dummy record to the struct
record.Map(&value, time.UTC)
t.Run("string", func(t *testing.T) {
got := value.String
expect := "string"
if got != expect {
t.Errorf("got: '%v', expected: '%v'", got, expect)
}
})
t.Run("int", func(t *testing.T) {
got := value.Int
var expect int = 100
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("int8", func(t *testing.T) {
got := value.Int8
var expect int8 = 8
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("int16", func(t *testing.T) {
got := value.Int16
var expect int16 = 16
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("int32", func(t *testing.T) {
got := value.Int32
var expect int32 = 32
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("int64", func(t *testing.T) {
got := value.Int64
var expect int64 = 64
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("float32", func(t *testing.T) {
got := value.Float32
var expect float32 = 32.32
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("float64", func(t *testing.T) {
got := value.Float64
var expect float64 = 64.64
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("bool_true_txt_test", func(t *testing.T) {
got := value.BoolTrueTxtTest
expect := true
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("bool_true_txt_false", func(t *testing.T) {
got := value.BoolTrueTxtFalse
expect := true
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("bool_false_txt", func(t *testing.T) {
got := value.BoolFalseTxt
expect := false
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("bool_true_num_1", func(t *testing.T) {
got := value.BoolTrueNum1
expect := true
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("bool_true_num_123", func(t *testing.T) {
got := value.BoolTrueNum123
expect := true
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("bool_false_num_0", func(t *testing.T) {
got := value.BoolFalseNum0
expect := false
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("date_1", func(t *testing.T) {
got := value.Date1
expect := time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC)
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("date_2", func(t *testing.T) {
got := value.Date2
expect := time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC)
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("timestamp_1", func(t *testing.T) {
got := value.Timestamp1
expect := time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("timestamp_2", func(t *testing.T) {
got := value.Timestamp2
expect := time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("time_invalid", func(t *testing.T) {
got := value.TimeInvalid
expect := time.Time{}
if got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("time_pointer", func(t *testing.T) {
got := value.TimePointer
expect := time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)
if got == nil || *got != expect {
t.Errorf("got: %v, expected: %v", got, expect)
}
})
t.Run("time_pointer_invalid", func(t *testing.T) {
got := value.TimePointerInvalid
if got != nil {
t.Errorf("got: %v, expected: %v", got, nil)
}
})
t.Run("nested_string", func(t *testing.T) {
got := value.Nested.String
expect := "string"
if got != expect {
t.Errorf("got: '%v', expected: '%v'", got, expect)
}
})
t.Run("nested_nested_string", func(t *testing.T) {
got := value.Nested.Nested.String
expect := "string"
if got != expect {
t.Errorf("got: '%v', expected: '%v'", got, expect)
}
})
t.Run("nested_pointer_string", func(t *testing.T) {
got := value.NestedStructPointer.String
expect := "string"
if got != expect {
t.Errorf("got: '%v', expected: '%v'", got, expect)
}
})
t.Run("nested_nil_pointer", func(t *testing.T) {
got := value.NestedNilStructPointer
if got != nil {
t.Errorf("got: %v, expected: %v", got, nil)
}
})
}