Skip to content

Testing

Nick edited this page Dec 21, 2022 · 1 revision

Integration testing

The integration tests are the most useful ones. They live in tests/integration/, and are notable because they boot a full copy of ./gitea and talk to it (via the HTTP web UI, via their HTTP API, via the git-over-ssh protocol, via the git HTTP protocol), instead of calling individual functions.

To run them, type (this is documented in CONTRIBUTING.md):

make test-sqlite

or use a prefix to limit which test functions run:

make test-sqlite#TestLFS
make test-sqlite#TestGitAnnex

Development

It's a bit tricky to debug or develop new tests because the Makefile does a bunch of arcane wizardry so that gitea comes up on ports 3003 (for the web UI, REST API, git-HTTP protocol) and :2203 (for git+ssh://), whereas by default it's normally on :3000 and isn't running its own ssh server at all, and it is running with its data in tests/integration/gitea-integration-sqlite instead of ./

Here's how to run the test environment in isolation:

  1. run make test-sqlite once to generate tests/sqlite.ini (and get a baseline for the current state of the tests)
  2. edit sqlite.ini to switch logging to 'MODE = console'; also, usually you should set logging LEVEL = debug
  3. ./gitea -c pwd/tests/sqlite.ini -C tests/integration/gitea-integration-sqlite/custom
  4. connect to http://localhost:3003
  5. log in as "user1" or "user2" or any of the other users with password "password"
  6. Upload an ssh key

You can inspect and edit the DB with sqlite3 tests/integration/gitea-integration-sqlite/gitea.db (you can inspect this after running make test-sqlite too, but it's more useful for development if you can edit the system interactively).

Fixtures

"Fixtures" in Gitea refers to database rows that get loaded. For extra kicks, they are provided as yaml files, just because. Fixtures are in models/fixtures/*.yml -- not in tests/ -- but they are key to the tests and are where the tests get their data. Each file is a list of dictionaries; the dictionaries become SQL rows, and each file is one SQL table.

There's also tests/gitea-repositories-meta/; this is sort of like a fixture too: it is all the on-disk git repositories. This folder gets copied to tests/integration/gitea-integration-sqlite/gitea-repositories/ when the tests start.

Pay attention to the _unit.yml files: these define permissions. Much will not work in GItea if the associated permissions are missing.

Clone this wiki locally