Possible to define a functionality that allows for custom defaults/generation #1131
Unanswered
michael-jaquier
asked this question in
Q&A
Replies: 2 comments
-
I feel like you are looking for the crate Arbitrary[https://docs.rs/arbitrary/latest/arbitrary/]
I think you could derive it automatically using prost-build. Let me know how that went, as I am interested in that as well.
It would be great if prost-types could derive arbitrary as well. That should be behind a feature flag. Are you willing to contribute that?
20 aug. 2024 15:19:11 Michael Jaquier ***@***.***>:
…
We have a litany of Protobufs. I would like the following to function
let mut rng = rand::thread_rng();
let my_proto: MyProto = MyProto.generate(&mut rng);
let my_proto_but_different: MyProto = MyProto.generate(&mut rng);
/// ... Do work with the proto -> Send it into system for smoke testing/testing purposes
The use case for us/me is the protos we utilize are often highly nested. The quantity of these protos makes it impractical to define some function like
pub fn generate_my_proto(rng: &mut rng) -> MyProto { ... }
Would something like so be acceptable? I believe I could create the necessary functionality behind a feature flag in code generation extending what is already create for *Default::default()* but would such a feature be accepted? There's no point in writing the code for it if it forces me to fork prost in perpetuity.
—
Reply to this email directly, view it on GitHub[#1131], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAJZ7OXMHT4MJOHMKVW2OBDZSM64ZAVCNFSM6AAAAABMZ4VWC2VHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXGA3TKMBSGI].
You are receiving this because you are subscribed to this thread.
[Tracking afbeelding][https://github.com/notifications/beacon/AAJZ7OR37CMJ2WDPXDXAUOLZSM64ZA5CNFSM6AAAAABMZ4VWC2WGG33NNVSW45C7OR4XAZNKIRUXGY3VONZWS33OVJRW63LNMVXHIX3JMTHAA27UZY.gif]
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Proptest is another library that can help, it provides more flexible generation strategies than Arbitrary, can shrink failure cases, and maintain a record of past regressions. proptest-derive provides the derive macro. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have a litany of Protobufs. I would like the following to function
The use case for us/me is the protos we utilize are often highly nested. The quantity of these protos makes it impractical to define some function like
Would something like so be acceptable? I believe I could create the necessary functionality behind a feature flag in code generation extending what is already create for
Default::default()
but would such a feature be accepted? There's no point in writing the code for it if it forces me to fork prost in perpetuity.Beta Was this translation helpful? Give feedback.
All reactions