diff options
author | Aravinth Manivannan <realaravinth@batsense.net> | 2022-07-04 18:06:24 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-04 14:36:24 +0200 |
commit | 2921d3c8c9ea17941e4da4381e6fb3177cd7d37d (patch) | |
tree | 1cd4fe1e5a4739c495d8807b540e0900c3beb478 /integrations/migrate_test.go | |
parent | ba0f9274e99ce7e28d587e30eee4a211b0556354 (diff) | |
download | gitea-2921d3c8c9ea17941e4da4381e6fb3177cd7d37d.tar.gz gitea-2921d3c8c9ea17941e4da4381e6fb3177cd7d37d.zip |
Add integration tests for the Gitea migration form (#20121)
* tests: integration tests for the Gitea migration form
* use a mix of ` and " instead of backslash
https://github.com/go-gitea/gitea/pull/20121#discussion_r906729415
Co-authored-by: Loïc Dachary <loic@dachary.org>
Diffstat (limited to 'integrations/migrate_test.go')
-rw-r--r-- | integrations/migrate_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/integrations/migrate_test.go b/integrations/migrate_test.go index 9b59c85a4e..f67e4ed229 100644 --- a/integrations/migrate_test.go +++ b/integrations/migrate_test.go @@ -5,12 +5,17 @@ package integrations import ( + "fmt" + "net/http" + "net/url" "os" "testing" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/services/migrations" "github.com/stretchr/testify/assert" @@ -40,3 +45,54 @@ func TestMigrateLocalPath(t *testing.T) { setting.ImportLocalPaths = old } + +func TestMigrateGiteaForm(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() + }() + assert.NoError(t, migrations.Init()) + + ownerName := "user2" + repoName := "repo1" + repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: ownerName}).(*user_model.User) + session := loginUser(t, ownerName) + token := getTokenForLoggedInUser(t, session) + + // Step 0: verify the repo is available + req := NewRequestf(t, "GET", fmt.Sprintf("/%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", structs.GiteaService) + resp := session.MakeRequest(t, req, http.StatusOK) + // Step 2: load the form + htmlDoc := NewHTMLParser(t, resp.Body) + 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", structs.GiteaService), + "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 + loc := resp.Header().Get("Location") + assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc) + // Step 6: check the repo was created + unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) + }) +} |