Repository: bxcodec/faker
Pull request #91 (2020-03-04 17:50:44)

fix: special slice types cause panic when reflectively generating values
The updated faker test will product the following without the convert update for slices.
```
panic: reflect.Set: value of type int32 is not assignable to type faker.SomeInt32 [recovered]
        panic: reflect.Set: value of type int32 is not assignable to type faker.SomeInt32

goroutine 34 [running]:
testing.tRunner.func1.1(0x1162b20, 0xc00017f960)
        /usr/local/Cellar/go/1.14/libexec/src/testing/testing.go:941 +0x3d0
testing.tRunner.func1(0xc000166240)
        /usr/local/Cellar/go/1.14/libexec/src/testing/testing.go:944 +0x3f9
panic(0x1162b20, 0xc00017f960)
        /usr/local/Cellar/go/1.14/libexec/src/runtime/panic.go:967 +0x15d
reflect.Value.assignTo(0x11622e0, 0xc00018402c, 0x85, 0x11a5a9a, 0xb, 0x1162220, 0x0, 0x33, 0xc000186000, 0x17)
        /usr/local/Cellar/go/1.14/libexec/src/reflect/value.go:2403 +0x426
reflect.Value.Set(0x1162220, 0xc000186000, 0x185, 0x11622e0, 0xc00018402c, 0x85)
        /usr/local/Cellar/go/1.14/libexec/src/reflect/value.go:1532 +0xbd
github.com/bxcodec/faker/v3.getValue(0x115f740, 0xc00000f820, 0x197, 0x1, 0x115f740, 0xc00000f820, 0x197)
        /Users/roarkegaskill/Developer/faker/faker.go:451 +0xd67
github.com/bxcodec/faker/v3.getValue(0x119c840, 0xc000128780, 0x199, 0x119c801, 0x119c840, 0xc000128780, 0x320)
        /Users/roarkegaskill/Developer/faker/faker.go:396 +0x22e1
github.com/bxcodec/faker/v3.getValue(0x116c9a0, 0xc000128280, 0x0, 0xc00005c980, 0x100c686, 0xc000128280, 0x280)
        /Users/roarkegaskill/Developer/faker/faker.go:355 +0x169e
github.com/bxcodec/faker/v3.FakeData(0x116c9a0, 0xc000128280, 0x11, 0xc00005ca70)
        /Users/roarkegaskill/Developer/faker/faker.go:280 +0x1c6
github.com/bxcodec/faker/v3.TestFakerData(0xc000166240)
        /Users/roarkegaskill/Developer/faker/faker_test.go:277 +0x5c
testing.tRunner(0xc000166240, 0x11b2650)
        /usr/local/Cellar/go/1.14/libexec/src/testing/testing.go:992 +0xdc
created by testing.(*T).Run
        /usr/local/Cellar/go/1.14/libexec/src/testing/testing.go:1043 +0x357
FAIL    github.com/bxcodec/faker/v3     0.148s
?       github.com/bxcodec/faker/v3/support/slice       [no test files]
FAIL
```


codecov[bot]: # [Codecov](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=h1) Report
> Merging [#91](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=desc) into [master](https://codecov.io/gh/bxcodec/faker/commit/7198e34fe9a1ca4ccfddd1686a0ec5cf5d1cd9cb?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/bxcodec/faker/pull/91/graphs/tree.svg?width=650&token=cLPGB7MHVc&height=150&src=pr)](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
+ Coverage   94.92%   94.92%   +<.01%     
==========================================
  Files          10       10              
  Lines         965      966       +1     
==========================================
+ Hits          916      917       +1     
  Misses         27       27              
  Partials       22       22
```


| [Impacted Files](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [faker.go](https://codecov.io/gh/bxcodec/faker/pull/91/diff?src=pr&el=tree#diff-ZmFrZXIuZ28=) | `90.37% <100%> (+0.02%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=footer). Last update [7198e34...209536a](https://codecov.io/gh/bxcodec/faker/pull/91?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/faker.go b/faker.go
index d9254f2..1844154 100644
--- a/faker.go
+++ b/faker.go
@@ -447,6 +447,7 @@ func getValue(a interface{}) (reflect.Value, error) {
 			if err != nil {
 				return reflect.Value{}, err
 			}
+			val = val.Convert(v.Index(i).Type())
 			v.Index(i).Set(val)
 		}
 		return v, nil


Test patch:
diff --git a/faker_test.go b/faker_test.go
index a134509..1375f85 100644
--- a/faker_test.go
+++ b/faker_test.go
@@ -14,6 +14,8 @@ const (
 	someStructBoundaryEnd   = 10
 )
 
+type SomeInt32 int32
+
 type SomeStruct struct {
 	Inta    int
 	Int8    int8
@@ -61,6 +63,8 @@ type SomeStruct struct {
 	MapStringString        map[string]string
 	MapStringStruct        map[string]AStruct
 	MapStringStructPointer map[string]*AStruct
+
+	SomeInt32s []SomeInt32
 }
 
 type SomeStructWithLen struct {