mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 15:02:43 +00:00
chore: improve slow tests
- Optimize generting random files. - Reduce big file of 128MiB to 32MiB (git was never made for large files anyways, but simply tests that it works). - Reduce looped git operations from 100 iterations to 10. - Add extra print statements to know what a slow test is doing, this also helps to see if a particular piece of code in a slow test is the culprit or if the test is just very extensive. - Set `[ui.notification].EVENT_SOURCE_UPDATE_TIME` to 1s to speed up `TestEventSourceManagerRun`. - Sneaked in some general test improvements.
This commit is contained in:
parent
9e95f80d94
commit
75a8b83946
13 changed files with 94 additions and 113 deletions
|
@ -5,7 +5,6 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -21,9 +20,10 @@ import (
|
|||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/services/migrations"
|
||||
"code.gitea.io/gitea/services/repository"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -58,16 +58,8 @@ func TestMigrateLocalPath(t *testing.T) {
|
|||
|
||||
func TestMigrate(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
AllowLocalNetworks := setting.Migrations.AllowLocalNetworks
|
||||
setting.Migrations.AllowLocalNetworks = true
|
||||
AppVer := setting.AppVer
|
||||
// Gitea SDK (go-sdk) need to parse the AppVer from server response, so we must set it to a valid version string.
|
||||
setting.AppVer = "1.16.0"
|
||||
defer func() {
|
||||
setting.Migrations.AllowLocalNetworks = AllowLocalNetworks
|
||||
setting.AppVer = AppVer
|
||||
migrations.Init()
|
||||
}()
|
||||
defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, true)()
|
||||
defer test.MockVariableValue(&setting.AppVer, "1.16.0")()
|
||||
require.NoError(t, migrations.Init())
|
||||
|
||||
ownerName := "user2"
|
||||
|
@ -82,42 +74,40 @@ func TestMigrate(t *testing.T) {
|
|||
{svc: structs.GiteaService},
|
||||
{svc: structs.ForgejoService},
|
||||
} {
|
||||
// Step 0: verify the repo is available
|
||||
req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
// Step 1: get the Gitea migration form
|
||||
req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
// Step 2: load the form
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
// Check form title
|
||||
title := htmlDoc.doc.Find("title").Text()
|
||||
assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title"))
|
||||
// Get the link of migration button
|
||||
link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
// Step 4: submit the migration to only migrate issues
|
||||
migratedRepoName := "otherrepo"
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
"service": fmt.Sprintf("%d", s.svc),
|
||||
"clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName),
|
||||
"auth_token": token,
|
||||
"issues": "on",
|
||||
"repo_name": migratedRepoName,
|
||||
"description": "",
|
||||
"uid": fmt.Sprintf("%d", repoOwner.ID),
|
||||
t.Run(s.svc.Name(), func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
// Step 0: verify the repo is available
|
||||
req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName)
|
||||
_ = session.MakeRequest(t, req, http.StatusOK)
|
||||
// Step 1: get the Gitea migration form
|
||||
req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
// Step 2: load the form
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
// Check form title
|
||||
title := htmlDoc.doc.Find("title").Text()
|
||||
assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title"))
|
||||
// Get the link of migration button
|
||||
link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
// Step 4: submit the migration to only migrate issues
|
||||
migratedRepoName := "otherrepo-" + s.svc.Name()
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
"service": fmt.Sprintf("%d", s.svc),
|
||||
"clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName),
|
||||
"auth_token": token,
|
||||
"issues": "on",
|
||||
"repo_name": migratedRepoName,
|
||||
"description": "",
|
||||
"uid": fmt.Sprintf("%d", repoOwner.ID),
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
// Step 5: a redirection displays the migrated repository
|
||||
assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), test.RedirectURL(resp))
|
||||
// Step 6: check the repo was created
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||
// Step 5: a redirection displays the migrated repository
|
||||
loc := resp.Header().Get("Location")
|
||||
assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc)
|
||||
// Step 6: check the repo was created
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
|
||||
|
||||
// Step 7: delete the repository, so we can test with other services
|
||||
err := repository.DeleteRepository(context.Background(), repoOwner, repo, false)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue