Add a simple test for AdoptRepository (#31391)

Follow #31333
pull/31299/head^2
wxiaoguang 5 months ago committed by GitHub
parent 129206da45
commit f5dfd7d73c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      services/repository/adopt_test.go

@ -6,10 +6,13 @@ package repository
import (
"os"
"path"
"path/filepath"
"testing"
"code.gitea.io/gitea/models/db"
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"
"github.com/stretchr/testify/assert"
@ -83,3 +86,13 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) {
assert.Equal(t, 2, count)
assert.Equal(t, unadoptedList[1], repoNames[0])
}
func TestAdoptRepository(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
assert.NoError(t, unittest.CopyDir(filepath.Join(setting.RepoRootPath, "user2", "repo1.git"), filepath.Join(setting.RepoRootPath, "user2", "test-adopt.git")))
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
_, err := AdoptRepository(db.DefaultContext, user2, user2, CreateRepoOptions{Name: "test-adopt"})
assert.NoError(t, err)
repoTestAdopt := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "test-adopt"})
assert.Equal(t, "sha1", repoTestAdopt.ObjectFormatName)
}

Loading…
Cancel
Save