code.gitea.io/gitea@v1.21.7/tests/integration/repo_migrate_test.go (about)

     1  // Copyright 2017 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"fmt"
     8  	"net/http"
     9  	"net/http/httptest"
    10  	"testing"
    11  
    12  	"code.gitea.io/gitea/modules/structs"
    13  	"code.gitea.io/gitea/tests"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *httptest.ResponseRecorder {
    19  	req := NewRequest(t, "GET", fmt.Sprintf("/repo/migrate?service_type=%d", structs.PlainGitService)) // render plain git migration page
    20  	resp := session.MakeRequest(t, req, http.StatusOK)
    21  	htmlDoc := NewHTMLParser(t, resp.Body)
    22  
    23  	link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
    24  	assert.True(t, exists, "The template has changed")
    25  
    26  	uid, exists := htmlDoc.doc.Find("#uid").Attr("value")
    27  	assert.True(t, exists, "The template has changed")
    28  
    29  	req = NewRequestWithValues(t, "POST", link, map[string]string{
    30  		"_csrf":      htmlDoc.GetCSRF(),
    31  		"clone_addr": cloneAddr,
    32  		"uid":        uid,
    33  		"repo_name":  repoName,
    34  		"service":    fmt.Sprintf("%d", structs.PlainGitService),
    35  	})
    36  	resp = session.MakeRequest(t, req, http.StatusSeeOther)
    37  
    38  	return resp
    39  }
    40  
    41  func TestRepoMigrate(t *testing.T) {
    42  	defer tests.PrepareTestEnv(t)()
    43  	session := loginUser(t, "user2")
    44  	testRepoMigrate(t, session, "https://github.com/go-gitea/test_repo.git", "git")
    45  }