diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-19 21:39:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 21:39:57 +0800 |
commit | fc3d0826096943b979717ed46c9a4cfd86e06106 (patch) | |
tree | 3143882ccf4dea3a8bf2a0de9c8da9a4efec26ce /models/repo_test.go | |
parent | 7a0347315995b25bcb2dca4786504fb699b5f004 (diff) | |
download | gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.tar.gz gitea-fc3d0826096943b979717ed46c9a4cfd86e06106.zip |
Move attachment into models/repo/ (#17650)
* Move attachment into models/repo/
* Fix test
* Fix bug
Diffstat (limited to 'models/repo_test.go')
-rw-r--r-- | models/repo_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/models/repo_test.go b/models/repo_test.go index ec1bcc0487..5cc396eb76 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -13,6 +13,7 @@ import ( "testing" "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" "code.gitea.io/gitea/modules/markup" @@ -224,3 +225,30 @@ func TestRepoGetReviewerTeams(t *testing.T) { assert.NoError(t, err) assert.Len(t, teams, 2) } + +func TestLinkedRepository(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + testCases := []struct { + name string + attachID int64 + expectedRepo *Repository + expectedUnitType unit.Type + }{ + {"LinkedIssue", 1, &Repository{ID: 1}, unit.TypeIssues}, + {"LinkedComment", 3, &Repository{ID: 1}, unit.TypePullRequests}, + {"LinkedRelease", 9, &Repository{ID: 1}, unit.TypeReleases}, + {"Notlinked", 10, nil, -1}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + attach, err := repo_model.GetAttachmentByID(tc.attachID) + assert.NoError(t, err) + repo, unitType, err := LinkedRepository(attach) + assert.NoError(t, err) + if tc.expectedRepo != nil { + assert.Equal(t, tc.expectedRepo.ID, repo.ID) + } + assert.Equal(t, tc.expectedUnitType, unitType) + }) + } +} |