diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-06-15 15:02:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-15 09:02:00 +0200 |
commit | d91d4db344792760a18265c6902d4ac909d0ee84 (patch) | |
tree | e32232b041671df97164c4398e48316744c32ceb /models/repo | |
parent | b4d420d8658feced78d897de4fbc9cc6ca76ab4e (diff) | |
download | gitea-d91d4db344792760a18265c6902d4ac909d0ee84.tar.gz gitea-d91d4db344792760a18265c6902d4ac909d0ee84.zip |
Move tests as seperate sub packages to reduce duplicated file names (#19951)
Diffstat (limited to 'models/repo')
-rw-r--r-- | models/repo/collaboration_test.go | 21 | ||||
-rw-r--r-- | models/repo/repo_test.go | 68 |
2 files changed, 89 insertions, 0 deletions
diff --git a/models/repo/collaboration_test.go b/models/repo/collaboration_test.go index 8cb7980a75..2e6253d561 100644 --- a/models/repo/collaboration_test.go +++ b/models/repo/collaboration_test.go @@ -8,6 +8,8 @@ import ( "testing" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/perm" + access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" @@ -48,3 +50,22 @@ func TestRepository_IsCollaborator(t *testing.T) { test(4, 2, false) test(4, 4, true) } + +func TestRepository_ChangeCollaborationAccessMode(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}).(*repo_model.Repository) + assert.NoError(t, repo_model.ChangeCollaborationAccessMode(repo, 4, perm.AccessModeAdmin)) + + collaboration := unittest.AssertExistsAndLoadBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4}).(*repo_model.Collaboration) + assert.EqualValues(t, perm.AccessModeAdmin, collaboration.Mode) + + access := unittest.AssertExistsAndLoadBean(t, &access_model.Access{UserID: 4, RepoID: repo.ID}).(*access_model.Access) + assert.EqualValues(t, perm.AccessModeAdmin, access.Mode) + + assert.NoError(t, repo_model.ChangeCollaborationAccessMode(repo, 4, perm.AccessModeAdmin)) + + assert.NoError(t, repo_model.ChangeCollaborationAccessMode(repo, unittest.NonexistentID, perm.AccessModeAdmin)) + + unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repo.ID}) +} diff --git a/models/repo/repo_test.go b/models/repo/repo_test.go index 8ae84eab52..6f8b282a66 100644 --- a/models/repo/repo_test.go +++ b/models/repo/repo_test.go @@ -9,7 +9,10 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/util" "github.com/stretchr/testify/assert" @@ -57,3 +60,68 @@ func TestRepoAPIURL(t *testing.T) { assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL()) } + +func TestWatchRepo(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + const repoID = 3 + const userID = 2 + + assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, true)) + unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID}) + unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID}) + + assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, false)) + unittest.AssertNotExistsBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID}) + unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID}) +} + +func TestMetas(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + repo := &repo_model.Repository{Name: "testRepo"} + repo.Owner = &user_model.User{Name: "testOwner"} + repo.OwnerName = repo.Owner.Name + + repo.Units = nil + + metas := repo.ComposeMetas() + assert.Equal(t, "testRepo", metas["repo"]) + assert.Equal(t, "testOwner", metas["user"]) + + externalTracker := repo_model.RepoUnit{ + Type: unit.TypeExternalTracker, + Config: &repo_model.ExternalTrackerConfig{ + ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}", + }, + } + + testSuccess := func(expectedStyle string) { + repo.Units = []*repo_model.RepoUnit{&externalTracker} + repo.RenderingMetas = nil + metas := repo.ComposeMetas() + assert.Equal(t, expectedStyle, metas["style"]) + assert.Equal(t, "testRepo", metas["repo"]) + assert.Equal(t, "testOwner", metas["user"]) + assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"]) + } + + testSuccess(markup.IssueNameStyleNumeric) + + externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric + testSuccess(markup.IssueNameStyleAlphanumeric) + + externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric + testSuccess(markup.IssueNameStyleNumeric) + + externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp + testSuccess(markup.IssueNameStyleRegexp) + + repo, err := repo_model.GetRepositoryByID(3) + assert.NoError(t, err) + + metas = repo.ComposeMetas() + assert.Contains(t, metas, "org") + assert.Contains(t, metas, "teams") + assert.Equal(t, "user3", metas["org"]) + assert.Equal(t, ",owners,team1,", metas["teams"]) +} |