bufaker — generate Faker-backed mock data for any Protobuf message from its protobuf-es descriptor #4698
pret-a-porter
started this conversation in
Show and tell
Replies: 0 comments
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.
I kept hand-writing test fixtures for Protobuf messages and getting bored, so I
built something to stop doing that: bufaker.
No per-message mapping code. It walks the runtime
DescMessagethatprotoc-gen-esemits and drives generation entirely offfield.fieldKind, soit works for any message you've generated — including ones it has never seen.
mock(PersonSchema)gives you a UUID inid, a real address inemail, a cityin
address.city, and exactly one branch of youroneofpopulated. Return typeis inferred as
MessageShape<Desc>, so nothing needs casting.What's covered:
*_UNSPECIFIEDby default), nestedmessages, repeated fields, maps, and oneofs
Timestamp,Duration, the*Valuewrappers,Struct/Value/ListValue,EmptymaxDepthguard, so self-referential and mutually recursive messagesterminate instead of blowing the stack
seedfor reproducible snapshots — including a pinned date reference, so agenerated
Timestampdoesn't drift with the wall clockScope, honestly: protobuf-es only, and that's deliberate rather than a TODO.
ts-protoand friends emit plain interfaces with no descriptor to reflect over,so there's nothing for this approach to walk. Tested against proto3.
google.protobuf.AnyandFieldMaskare left unset —Anyneeds a typeregistry to pick and pack a payload, and a random
FieldMaskcarries no meaning.It's 0.1.0, so the API may still move. Feedback very welcome, especially on the
override matching rules and whether the field-name heuristics being on by
default is the right call.
All reactions