google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
23.36k stars 3.25k forks source link

Go: Generate interface type for mocking #3779

Closed verokarhu closed 8 years ago

verokarhu commented 8 years ago

Generating an interface for the generated messages would make mocking them easier. Creating real messages or prefilling the message structs with data makes unit testing functions that use flatbuffers needlessly complicated.

ghost commented 8 years ago

Can you explain me why you would ever want to mock a FlatBuffers generated API? To test against the real API, all you need is a single buffer, or a single file (no moving parts, simple). To create a mock, you'd have to implement all the accessors, which is not only way more work, but it would break as soon as the schema changes since it is generated code.

rw commented 8 years ago

@verokarhu can you give a code example of how an interface would save you effort? I agree with @gwvo that this does not seem like it would help.

verokarhu commented 8 years ago

Actually, using files does sound simpler, I hadn't even considered that. I was afraid that hand-crafting buffers or building the messages with flatbuffers would be the only way, which sounded more tedious than implementing the accessors. Chalk it up to a lack of RTFM or maybe interface fever.

Thanks!