I'd like to hear about your approach to testing #6781
-
Hello. I'm a Japanese developer from IVIS Inc. and I'd like to hear about your approach to testing. We are forking your code and developing it to contribute to open science in Japan. My apologies if I have missed any documentation on this topic. However, if it is possible, I would like to know what the discussion was among the original "gogs" development team regarding this part of the test. Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @ivis-kuwata!
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 For testing API endpoints, my thinking is that, since all of these endpoints speak JSON, it is a good opportunities to actually do integration tests instead of unit tests (of course, more unit tests here won't hurt), do real business logic, hit the real database, etc. Hope this helps and happy to dig into more on this with you! |
Beta Was this translation helpful? Give feedback.
Hey @ivis-kuwata!
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 interfacecontext.Context
, which then becomes much easier to articulate mock states with mock implementations of thecontext.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…