@@ -119,6 +119,12 @@ func (c CustomMap) Fake(faker *gofakeit.Faker) (any, error) {
119
119
return CustomMap (map [string ]string {"hello" : "1" , "test" : "2" }), nil
120
120
}
121
121
122
+ type CustomArray [2 ]int
123
+
124
+ func (c CustomArray ) Fake (faker * gofakeit.Faker ) (any , error ) {
125
+ return CustomArray ([2 ]int {1 , 2 }), nil
126
+ }
127
+
122
128
type CustomStruct struct {
123
129
Str string
124
130
Int int
@@ -150,6 +156,7 @@ type NestedCustom struct {
150
156
Timestamp CustomTime
151
157
PtrTimestamp * CustomTime
152
158
SliceStr CustomSlice
159
+ Array CustomArray
153
160
MapStr CustomMap
154
161
Struct CustomStruct
155
162
PtrStruct * CustomStruct
@@ -174,6 +181,7 @@ type NestedOverrideCustom struct {
174
181
Timestamp CustomTime `fake:"{raw_test_date}"`
175
182
PtrTimestamp * CustomTime `fake:"{raw_test_date}"`
176
183
SliceStr CustomSlice `fake:"{word}"`
184
+ Array CustomArray `fake:"{number:100,1000}"`
177
185
MapStr CustomMap `fakesize:"2"`
178
186
}
179
187
@@ -423,6 +431,21 @@ func TestCustomMap(t *testing.T) {
423
431
}
424
432
}
425
433
434
+ func TestCustomArray (t * testing.T ) {
435
+ var d CustomArray
436
+ err := gofakeit .Struct (& d )
437
+ if err != nil {
438
+ t .Fatal (err )
439
+ }
440
+
441
+ expected := [2 ]int {1 , 2 }
442
+ for i , v := range expected {
443
+ if d [i ] != v {
444
+ t .Errorf ("expected item %d of the array to be: %v, got %v" , i , expected [i ], d [i ])
445
+ }
446
+ }
447
+ }
448
+
426
449
func TestCustomStruct (t * testing.T ) {
427
450
var d CustomStruct
428
451
err := gofakeit .Struct (& d )
@@ -510,6 +533,13 @@ func TestNestedCustom(t *testing.T) {
510
533
}
511
534
}
512
535
536
+ expectedArray := [2 ]int {1 , 2 }
537
+ for i , v := range expectedArray {
538
+ if d .Array [i ] != v {
539
+ t .Errorf ("expected item %d of the slice to be: %v, got %v" , i , expectedArray [i ], d .Array [i ])
540
+ }
541
+ }
542
+
513
543
expectedMap := map [string ]string {"hello" : "1" , "test" : "2" }
514
544
if len (d .MapStr ) != len (expectedMap ) {
515
545
t .Fatalf ("expected %v, got %v" , expectedMap , d )
@@ -644,6 +674,13 @@ func TestNestedOverrideCustom(t *testing.T) {
644
674
}
645
675
}
646
676
677
+ nonOverrideArray := [2 ]int {1 , 2 }
678
+ for i , v := range nonOverrideArray {
679
+ if d .Array [i ] == v {
680
+ t .Errorf ("Array: Got non-overriden item %d in the array" , i )
681
+ }
682
+ }
683
+
647
684
nonOverrideMap := map [string ]string {"hello" : "1" , "test" : "2" }
648
685
if len (d .MapStr ) == len (nonOverrideMap ) {
649
686
t .Logf ("Map: Got the same length as the non-overriden map: %v vs %v" , nonOverrideMap , d .MapStr )
0 commit comments