Skip to content

I'd like to hear about your approach to testing #6781

Answered by unknwon
ivis-kuwata asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @ivis-kuwata!

I'm wondering why there are no unit tests defined for functions that take *context.Context struct as an argument, in the internal/route/repo directory etc..

Very valid question, and a real problem indeed. It is very hard to mock a pointer struct in Go.

Speaking from my potential approach if I ever get chance to refactor the entire router layer 😅, I would convert the current *context.Context to an interface context.Context, which then becomes much easier to articulate mock states with mock implementations of the context.Context. https://github.com/derision-test/go-mockgen is the one I've used in other project to generate ergonomic mocks for interfaces.

For testing API e…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ivis-kuwata
Comment options

@unknwon
Comment options

Answer selected by ivis-kuwata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants