-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_test.go
623 lines (523 loc) · 20.2 KB
/
copy_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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
package mapper
import (
"context"
"encoding/json"
"fmt"
"math"
"reflect"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
/***************************
@author: tiansheng.ren
@date: 2022/10/25
@desc:
***************************/
var (
ctx = context.TODO()
defaultCopy = newCopyValue()
)
func TestBooleanCopyValue(t *testing.T) {
var result bool
srcValue := true
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.BooleanCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestIntCopyValue(t *testing.T) {
var result int
srcValue := 10
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.IntCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestInt64CopyValue(t *testing.T) {
var result int64
srcValue := 10
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.IntCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, int64(srcValue), result, "result not equal src value")
}
func TestUintCopyValue(t *testing.T) {
var result uint
srcValue := uint(10)
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.UintCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestUint64CopyValue(t *testing.T) {
var result uint64
srcValue := uint(10)
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.UintCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, uint64(srcValue), result, "result not equal src value")
}
func TestFloatCopyValue(t *testing.T) {
var result float64
srcValue := float64(10)
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.FloatCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestStringCopyValue(t *testing.T) {
var result string
srcValue := "test string copy value"
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StringCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestStringByteSliceCopyValue(t *testing.T) {
var result string
srcValue := []byte("test string copy value")
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StringCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, string(srcValue), result, "result not equal src value")
}
func TestStringByteSliceNilCopyValue(t *testing.T) {
var result string
var srcValue []byte = nil
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StringCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, string(srcValue), result, "result not equal src value")
}
func TestStrSliceCopyValue(t *testing.T) {
var result []string
srcValue := []string{"str1", "str2", "str3"}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.SliceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestNotZeroStrSliceCopyValue(t *testing.T) {
result := make([]string, 0)
srcValue := []string{"str1", "str2", "str3"}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.SliceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestIntSliceCopyValue(t *testing.T) {
var result []int
srcValue := []int{1, 2, 3, 4, 5, 6, 7}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.SliceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestNotZeroIntSliceCopyValue(t *testing.T) {
result := make([]int, 0)
srcValue := []int{1, 2, 3, 4, 5, 6, 7}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.SliceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestPtrIntSliceCopyValue(t *testing.T) {
result := []*int{}
srcValue := []int{1, 2, 3, 4, 5, 6}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.SliceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, len(srcValue), len(result), "result not equal src value")
require.Equal(t, srcValue[0], *result[0], "result not equal src value")
}
func TestPtrIntNilSliceCopyValue(t *testing.T) {
var result []*int = nil
srcValue := []int{1, 2, 3, 4, 5, 6}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.SliceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, len(srcValue), len(result), "result not equal src value")
require.Equal(t, srcValue[0], *result[0], "result not equal src value")
}
func TestPtrStrCopyValue(t *testing.T) {
var rawResult string
result := &rawResult
srcValue := "test ptr copy value"
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.PtrCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, *result, "result not equal src value")
}
func TestPtrStrNIlCopyValue(t *testing.T) {
var result *string = nil
srcValue := "test ptr copy value"
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.PtrCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, *result, "result not equal src value")
}
func TestPtrIntCopyValue(t *testing.T) {
var rawResult int
result := &rawResult
srcValue := 9999
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.PtrCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, *result, "result not equal src value")
}
func TestPtrIntNolCopyValue(t *testing.T) {
var result *int = nil
srcValue := 9999
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.PtrCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, *result, "result not equal src value")
}
func TestIntInterfaceCopyValue(t *testing.T) {
var result interface{}
srcValue := 999
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.InterfaceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestStrInterfaceCopyValue(t *testing.T) {
var result interface{}
srcValue := "test str interface copy value"
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.InterfaceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestMapInterfaceCopyValue(t *testing.T) {
var result interface{}
srcValue := map[string]string{"test": "test str interface copy value"}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.InterfaceCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestIntIntMapCopyValue(t *testing.T) {
var result map[int]int
srcValue := map[int]int{1: 1, 2: 2}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.MapCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
srcValue[1] = 11
require.Equal(t, 1, result[1], "result not equal src value")
}
func TestStrStrMapCopyValue(t *testing.T) {
var result map[string]string
srcValue := map[string]string{"1": "1", "2": "2"}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.MapCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestStrInterfaceMapCopyValue(t *testing.T) {
var result map[string]interface{}
srcValue := map[string]interface{}{"str": "str", "int": 2, "uint": int64(100), "ints": []int{1, 2, 3}, "strs": []string{"str", "str"}}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.MapCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue, result, "result not equal src value")
}
func TestMapStructMapCopyValue(t *testing.T) {
defaultCopy := newCopyValue()
defaultCopy.structCache.copyPrivate = true
type testS struct {
str string
int int
ints []int
}
stringTests := func(t testS) string {
return fmt.Sprintf("str: %s, int: %d, ints: %v", t.str, t.int, t.ints)
}
var result map[string]testS
srcValue := map[string]testS{
"tt": testS{
str: "str",
int: 1,
ints: []int{1, 2, 3},
},
}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.MapCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, stringTests(srcValue["tt"]), stringTests(result["tt"]), "result not equal src value")
}
func TestStructCopyValue(t *testing.T) {
type SrcStruct struct {
Int int `json:"int_copy"`
Strs []string
testPrivate string
}
type DstStruct struct {
IntCopy int `json:"int_copy"`
Strs []string
testPrivate string
}
srcValue := SrcStruct{Int: 1, Strs: []string{"str1", "str2"}, testPrivate: "test private"}
result := DstStruct{}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StructCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue.Int, result.IntCopy, "result not equal src value")
require.Equal(t, srcValue.Strs, result.Strs, "result not equal src value")
require.Equal(t, "", result.testPrivate, "result not equal src value")
}
func TestPrivateFieldStructCopyValue(t *testing.T) {
defaultCopy = newCopyValue()
defaultCopy.structCache.copyPrivate = true
type SrcStruct struct {
Int int `json:"int_copy"`
Strs []string
testPrivate string
}
type DstStruct struct {
IntCopy int `json:"int_copy"`
Strs []string
testPrivate string
}
srcValue := SrcStruct{Int: 1, Strs: []string{"str1", "str2"}, testPrivate: "test private"}
result := DstStruct{}
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StructCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue.Int, result.IntCopy, "result not equal src value")
require.Equal(t, srcValue.Strs, result.Strs, "result not equal src value")
require.Equal(t, srcValue.testPrivate, result.testPrivate, "result not equal src value")
}
func TestInlineStructCopyValue(t *testing.T) {
type inlineStruct struct {
A string
b string
}
type srcStruct struct {
inlineStruct
}
type dstStruct struct {
inlineStruct
}
srcValue := srcStruct{inlineStruct{
A: "inline a",
b: "inline b private field",
}}
result := dstStruct{}
defaultCopy := newCopyValue()
defaultCopy.structCache.copyPrivate = true
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StructCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue.A, result.A, "result not equal src value")
require.Equal(t, srcValue.b, result.b, "result not equal src value")
}
func TestMapToInlineStructCopyValue(t *testing.T) {
type inlineStruct struct {
A string
b string
}
type srcStruct struct {
inlineStruct
}
type dstStruct struct {
inlineStruct
}
srcValue := map[string]string{
"A": "inline a",
"b": "inline b private field",
}
result := dstStruct{}
defaultCopy := newCopyValue()
defaultCopy.structCache.copyPrivate = true
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.StructCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue["A"], result.A, "result not equal src value")
require.Equal(t, srcValue["b"], result.b, "result not equal src value")
}
func TestStructToMapMapCopyValue(t *testing.T) {
type inlineStruct struct {
A string
b string
}
type dstStruct struct {
inlineStruct
}
srcValue := dstStruct{
inlineStruct{
A: "inline a",
b: "inline b private field",
},
}
result := make(map[string]interface{}, 0)
defaultCopy := newCopyValue()
defaultCopy.structCache.copyPrivate = true
src, dst := reflect.ValueOf(srcValue), reflect.ValueOf(&result)
err := defaultCopy.MapCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue.A, result["A"], "result not equal src value")
require.Equal(t, srcValue.b, result["b"], "result not equal src value")
resultStrStr := make(map[string]string, 0)
src, dst = reflect.ValueOf(srcValue), reflect.ValueOf(&resultStrStr)
err = defaultCopy.MapCopyValue(ctx, src, dst.Elem())
require.NoError(t, err)
require.Equal(t, srcValue.A, resultStrStr["A"], "result not equal src value")
require.Equal(t, srcValue.b, resultStrStr["b"], "result not equal src value")
}
func TestJSONNumberCopyValue(t *testing.T) {
jsonNumber := reflect.ValueOf(json.Number("413"))
i64 := int64(0)
ui64, f := uint64(0), float64(0)
err := defaultCopy.IntCopyValue(ctx, jsonNumber, reflect.ValueOf(&i64).Elem())
require.NoError(t, err)
require.Equal(t, int64(413), i64, "json.Number to int64")
err = defaultCopy.UintCopyValue(ctx, jsonNumber, reflect.ValueOf(&ui64).Elem())
require.NoError(t, err)
require.Equal(t, uint64(413), ui64, "json.Number to uint64")
err = defaultCopy.FloatCopyValue(ctx, jsonNumber, reflect.ValueOf(&f).Elem())
require.NoError(t, err)
require.Equal(t, float64(413), f, "json.Number to float")
}
func TestMutualConversionIntegerToUintCopyValue(t *testing.T) {
suits := []struct {
src interface{}
dst interface{}
errContainContent string
tips string
}{
{src: int(1), dst: uint(0), tips: "int to uint"},
{src: int(1), dst: uint8(0), tips: "int to uint8"},
{src: int(1), dst: uint16(0), tips: "int to uint16"},
{src: int(1), dst: uint32(0), tips: "int to uint32"},
{src: int(1), dst: uint64(0), tips: "int to uint64"},
{src: int8(1), dst: uint8(0), tips: "int to uint8"},
{src: int16(1), dst: uint16(0), tips: "int to uint16"},
{src: int32(1), dst: uint32(0), tips: "int to uint32"},
{src: int64(1), dst: uint64(0), tips: "int to uint64"},
// test overflow
{src: int(-1), dst: uint(0), tips: "test overflows int to uint", errContainContent: "overflows"},
{src: int(-1), dst: uint8(0), tips: "test overflows int to uint8", errContainContent: "overflows"},
{src: int(-1), dst: uint16(0), tips: "test overflows int to uint16", errContainContent: "overflows"},
{src: int(-1), dst: uint32(0), tips: "test overflows int to uint32", errContainContent: "overflows"},
{src: int(-1), dst: uint64(0), tips: "test overflows int to uint64", errContainContent: "overflows"},
}
for idx, suit := range suits {
tips := fmt.Sprintf("index: %v, tip: %s", idx, suit.tips)
dst := reflect.ValueOf(&suit.dst).Elem()
dstVal := reflect.New(dst.Elem().Type())
err := defaultCopy.UintCopyValue(ctx, reflect.ValueOf(suit.src), dstVal.Elem())
if suit.errContainContent == "" {
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%v", suit.src), fmt.Sprintf("%v", dstVal.Elem().Interface()), tips)
} else {
if err == nil {
t.Errorf(tips + " error")
} else {
if !strings.Contains(err.Error(), suit.errContainContent) {
t.Errorf("tips: %s, err:%s", tips, err.Error())
}
}
}
}
}
func TestMutualConversionUnsignedToIntCopyValue(t *testing.T) {
suits := []struct {
src interface{}
dst interface{}
errContainContent string
tips string
}{
{src: uint(1), dst: int(0), tips: "uint to int"},
{src: uint(1), dst: int8(0), tips: "uint to int8"},
{src: uint(1), dst: int16(0), tips: "uint to int16"},
{src: uint(1), dst: int32(0), tips: "uint to int32"},
{src: uint(1), dst: int64(0), tips: "uint to int64"},
{src: uint8(1), dst: int(0), tips: "uint to int"},
{src: uint16(1), dst: int8(0), tips: "uint to int8"},
{src: uint32(1), dst: int16(0), tips: "uint to int16"},
{src: uint64(1), dst: int32(0), tips: "uint to int32"},
// test overflows
{src: uint(math.MaxUint64), dst: int(0), tips: "test overflows uint to int", errContainContent: "overflows"},
{src: uint(math.MaxUint8), dst: int8(0), tips: "test overflows uint to int8", errContainContent: "overflows"},
{src: uint(math.MaxUint16), dst: int16(0), tips: "test overflows uint to int16", errContainContent: "overflows"},
{src: uint(math.MaxUint32), dst: int32(0), tips: "test overflows uint to int32", errContainContent: "overflows"},
{src: uint(math.MaxUint64), dst: int64(0), tips: "test overflows uint to int64", errContainContent: "overflows"},
}
for idx, suit := range suits {
tips := fmt.Sprintf("index: %v, tip: %s", idx, suit.tips)
dst := reflect.ValueOf(&suit.dst).Elem()
dstVal := reflect.New(dst.Elem().Type())
err := defaultCopy.IntCopyValue(ctx, reflect.ValueOf(suit.src), dstVal.Elem())
if suit.errContainContent == "" {
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%v", suit.src), fmt.Sprintf("%v", dstVal.Elem().Interface()), tips)
} else {
if err == nil {
t.Errorf(tips + " error")
} else {
if !strings.Contains(err.Error(), suit.errContainContent) {
t.Errorf("tips: %s, err:%s", tips, err.Error())
}
}
}
}
}
func TestNilInterfaceToInterfaceCopyValue(t *testing.T) {
var src interface{}
var dst interface{}
err := defaultCopy.InterfaceCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&dst).Elem())
require.NoError(t, err, "test copy nil to nil ")
require.Equal(t, nil, dst, "test copy nil to nil ")
dst = "test"
err = defaultCopy.InterfaceCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&dst).Elem())
require.NoError(t, err, "test copy nil to nil ")
require.Equal(t, nil, dst, "test copy nil to nil ")
}
func TestInterfaceCanSetError(t *testing.T) {
var src interface{}
var dst interface{}
err := defaultCopy.InterfaceCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(dst))
require.Error(t, err, "InterfaceCopyValue copy to object must be pointers", "test copy nil to nil ")
if err != nil {
require.Equal(t, err.Error(), "InterfaceCopyValue copy to object must be pointers", "test copy nil to nil ")
}
}
func TestIntCanSetError(t *testing.T) {
src := 0
dst := 0
err := defaultCopy.IntCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(dst))
require.Error(t, err, "IntCopyValue copy to object must be pointers")
if err != nil {
require.Equal(t, err.Error(), "IntCopyValue copy to object must be pointers")
}
}
func TestInterfaceToMap(t *testing.T) {
var src interface{}
src = map[string]interface{}{"1": map[string]interface{}{"1": 1}}
dst := make(map[string]map[string]interface{}, 0)
err := defaultCopy.MapCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&dst).Elem())
require.NoError(t, err, "test copy interface to map")
require.Equal(t, fmt.Sprintf("%v", src), fmt.Sprintf("%v", dst), "test copy interface to map")
}
func TestInvalidToBuildInType(t *testing.T) {
var src interface{}
f64Dst, strDst, numDst, uNumDst, bDst := float64(2), "str", int64(2), uint64(2), true
err := defaultCopy.FloatCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&f64Dst).Elem())
require.NoError(t, err, "test copy interface to float")
require.Equal(t, int(2), int(f64Dst), "test copy invalid to float")
err = defaultCopy.StringCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&strDst).Elem())
require.NoError(t, err, "test copy interface to string")
require.Equal(t, "str", strDst, "test copy invalid to string")
err = defaultCopy.IntCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&numDst).Elem())
require.NoError(t, err, "test copy interface to int")
require.Equal(t, int(2), int(numDst), "test copy invalid to int")
err = defaultCopy.UintCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&uNumDst).Elem())
require.NoError(t, err, "test copy interface to uint")
require.Equal(t, int(2), int(uNumDst), "test copy invalid to uint")
err = defaultCopy.BooleanCopyValue(ctx, reflect.ValueOf(src), reflect.ValueOf(&bDst).Elem())
require.NoError(t, err, "test copy interface to bool")
require.Equal(t, true, bDst, "test copy invalid to bool")
}