fix: Use mock server for TestBreakConditions (#9948)

- Follow up of forgejo/forgejo!9274
- The test does not call to Gitea for fetching comments, but when initializing the Gitea client it does check the API version and some settings. Mock these responses so this test can be run without a network connection.
- Resolves forgejo/forgejo#9928

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9948
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-11-03 09:33:51 +01:00 committed by Gusted
parent 604a96107c
commit d6f7e154a1
3 changed files with 26 additions and 2 deletions

View file

@ -407,9 +407,15 @@ func createForgejoIssueComments(comments []*gitea_sdk.Comment) []*base.Comment {
}
func TestBreakConditions(t *testing.T) {
giteaToken := os.Getenv("GITEA_TOKEN")
fixturePath := "./testdata/gitea/breaking_conditions"
server := unittest.NewMockWebServer(t, "https://gitea.com", fixturePath, giteaToken != "")
defer server.Close()
// Client
giteaClient, err := gitea_sdk.NewClient(
"https://gitea.com",
server.URL,
gitea_sdk.SetToken(""),
gitea_sdk.SetBasicAuth("", ""),
gitea_sdk.SetContext(t.Context()),
@ -418,7 +424,7 @@ func TestBreakConditions(t *testing.T) {
require.NoError(t, err, "Clould not create Client")
// Downloader
downloader, err := NewGiteaDownloader(t.Context(), giteaClient, "https://gitea.com", "gitea/test_repo")
downloader, err := NewGiteaDownloader(t.Context(), giteaClient, server.URL, "gitea/test_repo")
if downloader == nil {
t.Fatal("NewGiteaDownloader is nil")
}

View file

@ -0,0 +1,9 @@
Alt-Svc: h3=":443"; ma=2592000
Content-Type: application/json;charset=utf-8
Vary: Origin
Content-Length: 155
Cache-Control: max-age=0, private, must-revalidate, no-transform
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
{"max_response_items":50,"default_paging_num":10,"default_git_trees_per_page":1000,"default_max_blob_size":10485760,"default_max_response_size":104857600}

View file

@ -0,0 +1,9 @@
X-Frame-Options: SAMEORIGIN
Content-Length: 41
Cache-Control: max-age=0, private, must-revalidate, no-transform
Content-Type: application/json;charset=utf-8
Alt-Svc: h3=":443"; ma=2592000
Vary: Origin
X-Content-Type-Options: nosniff
{"version":"1.25.0+dev-376-g223205cc6b"}