aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-06-17 09:18:35 +0800
committerGitHub <noreply@github.com>2024-06-17 01:18:35 +0000
commitf5dfd7d73cbc606ae65e5bab33efad1604b6331e (patch)
tree245dc12e0436dd2ecb89cd6301a1e34b4351e407 /services/repository
parent129206da4543f2024601af20dac3eaf978d0c432 (diff)
downloadgitea-f5dfd7d73cbc606ae65e5bab33efad1604b6331e.tar.gz
gitea-f5dfd7d73cbc606ae65e5bab33efad1604b6331e.zip
Add a simple test for AdoptRepository (#31391)
Follow #31333
Diffstat (limited to 'services/repository')
-rw-r--r--services/repository/adopt_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go
index c1520e01c9..38949c7602 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)
+}