-
-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a context usable in tests #349
Labels
good first issue
Good for newcomers
Comments
@EwenQuim Mind if I take this issue? |
If you want it, it's yours! As usual (not fun but very helpful), don't forget tests and documentation. Happy coding! 🔥 |
Thanks @EwenQuim 😊 |
olisaagbafor
added a commit
to olisaagbafor/fuego
that referenced
this issue
Jan 13, 2025
Add MockContext[B] to help users test their controllers without framework dependencies. Includes realistic examples and documentation. - Move testing docs from README.md to TESTING.md - Add mock context with getters/setters - Add example user controller tests - Use fuego_test package for end-user perspective Closes go-fuego#349
olisaagbafor
added a commit
to olisaagbafor/fuego
that referenced
this issue
Jan 13, 2025
Replace basic getter/setter tests with a real-world example: - Add UserController with Create and GetByID endpoints - Add UserService with mock implementation - Show proper separation of concerns - Demonstrate practical testing patterns - Move testing docs from README.md to TESTING.md This provides users with a clear example of how to test their controllers using the mock context in a real-world scenario. Closes go-fuego#349
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Each framework (
net/http
,gin
...) have a private context struct that respects theContextWithBody[B]
interface.But when testing your controller that have the
func (c ContextWithBody[B]) (T, error)
signature, we need a struct that respect this interface. Currently, users have to provide their struct, like inexamples/gin-compat/main_test.go
.Describe the solution you'd like
That we provide a
ContextMock[B]
with aurl.Values
and aBody B
that the user can simply fill in its tests, like inextra/fuegogin/context_mock.go
but router-agnostic.For the user, that means that he's testing his logic and not the framework: he trusts our serialization, validation etc...
That makes users more Fuego-dependant, which is not a good thing, but it's also more convenient than to use httptest and rewrite all utils. This also feels weird if the user have controllers that they cannot directly test.
The text was updated successfully, but these errors were encountered: