| ▲ | spenczar5 2 days ago | |||||||||||||
"But accepting the full S3Client here ties UploadReport to an interface that’s too broad. A fake must implement all the methods just to satisfy it." This isn't really true. Your mock inplementation can embed the interface, but only implement the one required method. Calling the unimplemented methods will panic, but that's not unreasonable for mocks. That is:
You don't have to implement all the other methods.Defining a zillion interfaces, all the permutations of methods in use, makes it hard to cone up with good names, and thus hard to read. | ||||||||||||||
| ▲ | lenkite a day ago | parent | next [-] | |||||||||||||
Not to mention, introducing all the permutations of methods as separate interfaces on the "consumer side" means extreme combinatorial explosion of interfaces. It is far better to judge the most common patterns and make single-method interfaces for these on the provider side. Lots of such frequently-quoted Go "principles" are invalid and are regularly broken within the standard library and many popular Go projects. And if you point them out, you will be snootily advised by the Go gurus on /r/golang or even here on HN that every principle has exceptions. (Even if there are tens of thousands of such exceptions). | ||||||||||||||
| ▲ | skybrian 2 days ago | parent | prev | next [-] | |||||||||||||
While you can do that, having unused methods that don't work is a footgun. It's cleaner if they don't exist at all. | ||||||||||||||
| ▲ | the_gipsy 2 days ago | parent | prev [-] | |||||||||||||
Is this pattern commonly used? Any drawbacks? Sounds much better than the interface boilerplate if it's just for the sake of testing. | ||||||||||||||
| ||||||||||||||