Remove external service dependencies in migration tests#36866
Remove external service dependencies in migration tests#36866silverwind merged 2 commits intogo-gitea:mainfrom
Conversation
|
But you shouldn't use it to test itself. What if the API breaks? The tests succeed, but it causes problems when released. |
|
So just write a HTTP-level mock that replicates what gitea.com currently does? I'll try that. |
|
I think yes. Maybe the work can start without waiting for gitea.com, indeed there are other tests needing such feature, e.g.: gitlab, github |
|
There was a tool that could record the traffic and mock the replies from the server... I'm trying to find it since it be interesting for this. |
|
I don't think we need such tools. Just a proper HTTP mock in go should do and AI can determine exactly what's needed for this test to pass. |
|
Found it. Not sure if it'll be useful but linking just in case https://keploy.io/docs/keploy-explained/why-keploy/ |
|
Here's the repo: https://github.com/keploy/keploy. Seems interesting but definitely out of scope for gitea right now. |
|
Can be done like this https://codeberg.org/forgejo/forgejo/commits/branch/forgejo/models/unittest/mock_http.go https://codeberg.org/forgejo/forgejo/src/branch/forgejo/models/unittest/mock_http.go The license is still MIT, so can just copy |
That server has some sort of "live mode" toggle based on the presence of an auth token where it rewrites test fixtures. Essentially it's similar to snapshot testing (but more manual), which you had rejected earlier. Current approach now has the minimal JSON responses inline using |
Really? Which comment? I think there are some misunderstandings. |
|
I think I have explained clearly:
If you use "go-snaps", then the test data causing failure will just be blindly updated to make tests pass. But here, if you have the mock server with live mode, you first test against the live servers, then capture the test data. Nobody can blindly update the test data. They are totally different. |
|
Not that different to me, but let's see what Claude comes up if I implement that pattern. |
|
The difference is whether you have a trust source which can provide the facts!! Mocked data with live server: the live server is the trust source. Your "go-snaps": you can blindly use the untrusted test output to update the test data without verifying them in many cases. I hope you can understand the difference. |
|
Rewrite still in progress. Once tidbit that was noticed is the Forgejo test does not actually test the cloning of the repo so it's incomplete. |
|
Implemented that mechansim, now we can run To record and update the test fixtures. |
Test_MigrateFromGiteaToGitea
|
I also checked other tests for external dependencies and there are a few:
Maybe we should also use |
Test_MigrateFromGiteaToGitea|
All migration tests now follow this scheme. If a token is provided they go into live mode, otherwise they use the recorded fixtures.
None of the remaining integration tests have dependencies on external services now (only local services like database etc). |
|
Updates on that? |
TheFox0x7
left a comment
There was a problem hiding this comment.
@silverwind Can you rerun/fix the gitlab test so the asserts aren't removed?
Blocking until then so it won't get merged with missing asserts compared to main
Done in 9c7c1d0. Ready for review. |
|
@TheFox0x7 please re-check. |
TheFox0x7
left a comment
There was a problem hiding this comment.
We get PR 6 but test reviews on PR 1
I know you can't exactly control which gets pulled from gitlab but the previous one was more comprehensive and should be kept IMO - so maybe or fetch two and compare the closed and unmerged and the approved and merged one?
There's also the date change in reviews but I have no idea why it happened (both seem wrong to me) so it's probably fine.
|
Done in cfbe630 and re-reviewed all other fixtures, all successful. |
TheFox0x7
left a comment
There was a problem hiding this comment.
Not exactly what I had in mind but on reading the raw gitlab test code instead of a diff I think issue assert covers what I wanted so it's fine as is IMO.
Replace live calls to gitea.com, github.com, gitlab.com, codebase, gogs, and onedev with a fixture-based HTTP mock server under models/unittest. Fixtures are committed so the default run is offline; live/record mode is gated on an API-token env var per service. Test_MigrateFromGiteaToGitea additionally serves its git data via an in-process git-http-backend backed by a deterministic fast-import stream, and simulates the PR fork repository so the head branch resolves without a second upstream dependency. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
* origin/main: Allow fast-forward-only merge when signed commits are required (go-gitea#37335) Introduce `ActionRunAttempt` to represent each execution of a run (go-gitea#37119) Move review request functions to a standalone file (go-gitea#37358) Fix repo init README EOL (go-gitea#37388) Fix org team assignee/reviewer lookups for team member permissions (go-gitea#37365) Remove external service dependencies in migration tests (go-gitea#36866) Extend issue context popup beyond markdown content (go-gitea#36908) # Conflicts: # routers/api/v1/repo/action.go # web_src/js/components/RepoActionView.vue
* origin/main: (127 commits) Refactor pull request view (1) (go-gitea#37380) Improve AGENTS.md (go-gitea#37382) Remove dead CSS (go-gitea#37376) Add pr-review e2e test and speed up e2e tests (go-gitea#37345) Drop Fomantic tab, checkbox and form patches (go-gitea#37377) fix: dump with default zip type produces uncompressed zip (go-gitea#37401) Allow fast-forward-only merge when signed commits are required (go-gitea#37335) Introduce `ActionRunAttempt` to represent each execution of a run (go-gitea#37119) Move review request functions to a standalone file (go-gitea#37358) Fix repo init README EOL (go-gitea#37388) Fix org team assignee/reviewer lookups for team member permissions (go-gitea#37365) Remove external service dependencies in migration tests (go-gitea#36866) Extend issue context popup beyond markdown content (go-gitea#36908) fix: commit status reporting (go-gitea#37372) Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356) Fix cmd tests by mocking builtin paths (go-gitea#37369) chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374) Fix button layout shift when collapsing file tree in editor (go-gitea#37363) Update `Block a user` form (go-gitea#37359) Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364) ... # Conflicts: # modules/eventsource/event.go # tests/e2e/events.test.ts
* origin/main: (51 commits) Fix color regressions, add `priority` color (go-gitea#37417) [skip ci] Updated translations via Crowdin Stabilize e2e logout propagation test (go-gitea#37403) refactor: serve site manifest via `/assets/site-manifest.json` endpoint (go-gitea#37405) feat(security): set X-Content-Type-Options: nosniff by default (go-gitea#37354) Refactor pull request view (1) (go-gitea#37380) Improve AGENTS.md (go-gitea#37382) Remove dead CSS (go-gitea#37376) Add pr-review e2e test and speed up e2e tests (go-gitea#37345) Drop Fomantic tab, checkbox and form patches (go-gitea#37377) fix: dump with default zip type produces uncompressed zip (go-gitea#37401) Allow fast-forward-only merge when signed commits are required (go-gitea#37335) Introduce `ActionRunAttempt` to represent each execution of a run (go-gitea#37119) Move review request functions to a standalone file (go-gitea#37358) Fix repo init README EOL (go-gitea#37388) Fix org team assignee/reviewer lookups for team member permissions (go-gitea#37365) Remove external service dependencies in migration tests (go-gitea#36866) Extend issue context popup beyond markdown content (go-gitea#36908) fix: commit status reporting (go-gitea#37372) Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356) ...
Fix #36859
Replace live third-party API calls in migration tests with a fixture-based HTTP mock server. Fixtures are committed so tests run offline by default; live recording is gated per service on an API-token env var.
This PR was written with the help of Claude Opus 4.7