Repository navigation
Make[T](): add support for field and type overrides - #72
Conversation
| v := g.gen.value(t) | ||
| if v == nil { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
I was seeing nil pointer exceptions in cases where v was nil. After double checking reflect.ValueOf I suspect the issue stems from reflect.Value.Convert as reflect.ValueOf(nil) returns a zero reflect.Value.
I'll add a comment and/or I could change this to:
v := reflect.ValueOf(g.gen.value(t))
if v.IsNil() {
return nil
}
return v.Convert(g.type).Interface()There was a problem hiding this comment.
In what cases .value() is nil? It should not be, ever.
There was a problem hiding this comment.
Ah! I figured it out. I was attempting to skip over a pointer field but missed the * so I had overridden a struct generator with rapid.Just[any](nil). I'll see if I can make the error message a bit more friendly and add a regression test.
|
Can you please separate this PR in two parts, support for private fields and type/field customization? Also, please make sure the CI tests all pass. |
This commit introduces the `MakeCustom[T](MakeConfig)` function which allows overriding the generation of specific types or the generation of specific fields on specific types. This ability allows users to leverage the convenience of `Make` on highly nested types that may have, for example, a string type that should be treated as an enum. Make now ignores private fields instead of panicking due to reflect's inability to set private fields.
|
Merged! Thanks. |
👋 I was utilizing rapid for a test involving Kubernetes objects (
corev1.Pod) and wanted to leverageMakeinstead of hand writing all the generation. I was transitioning the tests away from go-fuzz which provides the abilities to skip various fields and override "fuzzing" of others. This PR extends rapid to support a similar feature set.I'm already using this change in my fork and it works quite well. I'm not overjoyed with the API though but it does get the job done. If you have any suggestions, I'm all ears.