From f5dfd7d73cbc606ae65e5bab33efad1604b6331e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 17 Jun 2024 09:18:35 +0800 Subject: [PATCH] Add a simple test for AdoptRepository (#31391) Follow #31333 --- services/repository/adopt_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go index c1520e01c..38949c760 100644 --- a/services/repository/adopt_test.go +++ b/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) +}