Skip to content

test: run integration tests against a real server on every pull request - #8651

Merged
unknwon merged 6 commits into
mainfrom
integration-tests
Nov 17, 2026
Merged

unknwon merged 6 commits into
mainfrom
integration-tests

Conversation

@unknwon

@unknwon unknwon commented Nov 17, 2026

Copy link
Copy Markdown
Member

Describe the pull request

Adds integration tests that run against a real Gogs server on every pull request, and fixes the 10 bugs they found.

  • internal/integrationtest builds Gogs, starts gogs web on a new Postgres database with a configuration of its own, and calls it over HTTP. The test process loads the same configuration, so tests seed data through the stores and read what the server stores, e.g., captcha text from the session files and TOTP secrets, recovery codes and activation codes from the database. None of this code is built into Gogs.
  • A full run fails when any route gets no request from a test. The suite lists every route by parsing the router setup in the source, and the server exports a span for every request it handles. Routes that render pages of the web app are left out, so the suite needs no frontend build. 370 routes are covered by 151 tests, which check response content and the resulting state in the database or in Git, plus the main access boundary of each route.
  • .github/workflows/integration.yml runs the suite on Postgres 17 on every pull request, and moon run gogs:test-integration runs it locally.

Bugs fixed:

  • API v1 responds with 404 instead of 500 for a missing SSH key, Git blob, or branch or tag reference.
  • API v1 responds with 422 instead of 500 when creating a repository with a name the owner already uses.
  • Writing contents through API v1 to an existing branch other than the default one no longer fails.
  • Created labels report their IDs instead of 0, in API v1 and the web API.
  • API v1 lists the real mode of each Git tree entry, e.g., 100644 instead of 120000 for a regular file.
  • Deleting an editor upload that is already gone no longer fails.
  • /user/activate_email redirects to the email settings with ?activated=1 instead of an escaped path, and /user/email2user redirects to the profile instead of a page that is not found.

Link to the issue: n/a

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)

Test plan

  1. GOGS_INTEGRATION_TEST=1 PGHOST=localhost PGPORT=5432 PGUSER=postgres PGPASSWORD=... PGSSLMODE=disable go test -count=1 -shuffle=on ./internal/integrationtest/ passes on Postgres 15 with every route covered, and drops its database afterwards. It also passed with public/dist removed.
  2. Each bug fix has a test that failed before the fix.
  3. Breaking session ID regeneration on sign-in, or the read check of private repositories, makes the matching tests fail.
  4. go test ./internal/database/ ./internal/git/ ./internal/route/api/v1/ passes, and golangci-lint run reports 0 issues.

AI usage

Written with Amp, including parallel subagents for the tests of each area of routes. Reviewed and run as described above.

- Missing SSH keys, Git blobs and references are 404 rather than 500.
- Created labels report their IDs.
- Git trees list each entry's real mode.
- Creating a repository with a taken name through API v1 is 422.
- Writing contents to an existing non-default branch works.
- Deleting an upload that is already gone no longer fails.
- /user/activate_email and /user/email2user redirect to the right pages.
The suite builds Gogs, starts it on Postgres and calls it over HTTP. Tests
share the server's database and session files, so they seed data through
the stores and read secrets, e.g., captcha text and TOTP secrets. A full
run fails when any route other than a page of the web app gets no request,
judged by the server's request spans. Runs on every pull request.
@mintlify

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Gogs 🟢 Ready View Preview Nov 17, 2026, 4:17 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

Drop the test database after terminating its connections rather than with
DROP DATABASE WITH (FORCE), which needs PostgreSQL 13, and run CI on the
minimum supported version.
Rename the package to integrationtests and update the paths in CI, the
moon task and the local development docs.
@unknwon
unknwon merged commit 7b60cbc into main Nov 17, 2026
15 checks passed
@unknwon
unknwon deleted the integration-tests branch November 17, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant