From d6f7e154a15d5c79ed7260d46fcb51d5cb80a478 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 3 Nov 2025 09:33:51 +0100 Subject: [PATCH] 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 Co-authored-by: Gusted Co-committed-by: Gusted --- services/migrations/gitea_downloader_test.go | 10 ++++++++-- .../GET_%2Fapi%2Fv1%2Fsettings%2Fapi | 9 +++++++++ .../breaking_conditions/GET_%2Fapi%2Fv1%2Fversion | 9 +++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fsettings%2Fapi create mode 100644 services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fversion diff --git a/services/migrations/gitea_downloader_test.go b/services/migrations/gitea_downloader_test.go index df734c3ace..a4a4f29ddb 100644 --- a/services/migrations/gitea_downloader_test.go +++ b/services/migrations/gitea_downloader_test.go @@ -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") } diff --git a/services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fsettings%2Fapi b/services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fsettings%2Fapi new file mode 100644 index 0000000000..87fb421d8e --- /dev/null +++ b/services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fsettings%2Fapi @@ -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} diff --git a/services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fversion b/services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fversion new file mode 100644 index 0000000000..341ab432e3 --- /dev/null +++ b/services/migrations/testdata/gitea/breaking_conditions/GET_%2Fapi%2Fv1%2Fversion @@ -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"}