derision-test / go-mockgen

MIT License
57 stars 7 forks source link

Panic on unmocked method #15

Closed camdencheek closed 2 years ago

camdencheek commented 2 years ago

Rather than returning the zero-value for unmocked methods, I often want my mocks to be very loud when a method is called on them that I haven't mocked out. As far as I can tell, the only way to do that is either (1) mock every method with a panic manually, or (2) create a "panic on everything type" and then wrap it with NewMockXFrom(panicOnEverythingType{}).

I've been thinking it might be nice to include support for generating panicking types in go-mockgen. I can think of two ways to do that. (A) generate another constructor like NewPanickingMockX, or (B) add a configuration parameter that lets you generate the NewMockX constructor as the panicking version, like go-mockgen -when-unmocked panic or go-mockgen -when-unmocked zerovalue (the current behavior).

Thoughts on whether you think something like this might be worth adding?

camdencheek commented 2 years ago

Awesome -- thanks @efritz!