Hacker News new | ask | show | jobs
by venantius 2813 days ago
By authoring private structs with public constructors, you can get what you want out of this. Gets a bit messy with testing, but not impossible.
1 comments

If you have your tests within the same package, they can access the private members of structs directly, which helps avoid some of the mess.

If you’re in a different package things aren’t too bad if you have meaningfully abstracted interfaces. And with Go’s duck typing, even if you’re using another package that doesn’t have good abstraction, you can create your own interfaces with the functionality you need for mocking purposes.