-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Make customization #64
Comments
When I designed type Drawable interface {
Draw(t *rapid.T)
} This seems simpler to understand and use than allowing type-specific overrides specific to each I hope that this interface-based design can be good enough extensibility story, and for anything more complex |
It's probably slightly simpler to understand and probably moderately simpler to implement (doing type-detection based on generics well would prefer golang/go#54393 but it can be done hackily without that, I think).
Tend to agree here, field-specific overrides maybe don't make a lot of sense with the interfaces defined in rapid. I may not have been clear here though: the overrides wasn't to solve the problem of "let me set private fields" and instead is trying to let me specify the minimal set of generators rather than do them all by hand. With at least type-specific overrides to the reflection run by
The amount of work/maintenance to just supply a construction mechanism for time's via some override, versus use How open are you to either |
I am open to interface-based extensibility here because it does not change or complicate the meaning of As for per-call overrides, I feel that while it has more flexibility, and may help with your use-case more, it will enourage people to expect By the way, how much of your problem will be solved if rapid would have built-in |
There are two things causing
I'll be honest: this is somewhat what I was trying to use it for, as an alternative to gopter arbitraries. Gopter doesn't seem to have been updated much recently and arbitraries is really slow in comparison to
k, let me play around with my requirements and I may send a PR. I'll also consider sending a PR for built-in |
Make should work for recursive types, if it does not — can you open a separate issue with a reproducer for that? As for time.Time, that would require durations (trivial) and locations as well. Probably a good idea to research what Hypothesis is doing, as well as jqwik and others. |
yes, I believe that it would. I have a similar change that I was prototyping here but got sidetracked and never finished it. |
Apologies for not search through the issues before opening the pull request. @matthchr if you have any requests/suggestions/feedback on the linked PR I'm all ears. |
The change in #72 greatly simplified using rapid for my use case, which is testing gRPC parsing code. The gRPC generated types have private fields that are just interfaces, which caused As an example: lightninglabs/taproot-assets@8b579da Default empty constructors for private fields (inherited by all the custom Setting generators for gRPC message members: So this makes |
No apologies needed! I never got around to submitting a PR. I took at look at your PR and it seems good to me, I don't have much feedback other than it would be useful and I hope it's accepted/merged as I'll likely make use of it. |
I'd like to use
rapid.Make
to generate structs. It already does this great for simple structures, but in my case the structure I'd like to generate is quite complex:These facts mean that by default
Make
doesn't work for me.One possible solution is that I use
Custom
instead and build my struct that way. I'm very new to rapid but as far as I can tell that requires me explicitly build each section of this structure. This is possible but a lot of work.Instead, it would be nice if I could customize
Make
by overriding the default generators, but only for certain types or certain fields. gopter arbitraries has a similar capability.Naïvely, something like
Make[V any](overrides ...*Generator[any]) *Generator[V]
might work, where in my test I could first set up the overrides I know that I need, and then callMake
and supply them, and it would prefer the overrides but fall back to the defaults. Obviously if there's a desire to avoid changing the signature ofMake
, a variant could be used instead.The disadvantage of this approach is that it allows type overrides but doesn't achieve field-specific overrides. To achieve a field specific override you'd need to override the type the field resided on and use
Custom
to generate the whole struct. I suppose aMakeVariant
(ignore the name) could take(overrides []*Generator[any], fieldOverrides []*FieldGenerator[any])
whereI'm not sure that the field-specific override really fits the interfaces that you have defined well, but at least the type-specific one feels like it would slot in quite nicely.
Thoughts? Is there some way to do this already that I just haven't noticed?
The text was updated successfully, but these errors were encountered: