Code walkthrough: Gitea integration tests

This is one of the Code walkthrough I wrote while exploring the Gitea codebase.

Gitea integration tests are designed to run realistic scenarios with various databases (SQLite, MySQL, …), which unit tests do not do (yet).

For instance, the TestAPIOrgCreate test is wrapped in the onGiteaRunTB function. Before running, the tests is starts an http.Server and with routes bound to web.Route, effectively emulating a running Gitea API server.

The database is prepared by loading fixtures which create users etc. The database is reset entirely before every test: there is no risk of unexpected spillover between tests.

The NewRequestWithJSON helper (there are other similar helpers) is used to build a request. It is then given as an argument to MakeRequest which records the call before passing it to ServeHTTP.

2 Likes