summaryrefslogtreecommitdiffstats
path: root/models/attachment_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/attachment_test.go')
-rw-r--r--models/attachment_test.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/models/attachment_test.go b/models/attachment_test.go
index f38a5beeee..ddb6abad32 100644
--- a/models/attachment_test.go
+++ b/models/attachment_test.go
@@ -61,7 +61,7 @@ func TestGetByCommentOrIssueID(t *testing.T) {
// count of attachments from issue ID
attachments, err := GetAttachmentsByIssueID(1)
assert.NoError(t, err)
- assert.Equal(t, 2, len(attachments))
+ assert.Equal(t, 1, len(attachments))
attachments, err = GetAttachmentsByCommentID(1)
assert.NoError(t, err)
@@ -73,7 +73,7 @@ func TestDeleteAttachments(t *testing.T) {
count, err := DeleteAttachmentsByIssue(4, false)
assert.NoError(t, err)
- assert.Equal(t, 1, count)
+ assert.Equal(t, 2, count)
count, err = DeleteAttachmentsByComment(2, false)
assert.NoError(t, err)
@@ -128,3 +128,31 @@ func TestGetAttachmentsByUUIDs(t *testing.T) {
assert.Equal(t, int64(1), attachList[0].IssueID)
assert.Equal(t, int64(5), attachList[1].IssueID)
}
+
+func TestLinkedRepository(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+ testCases := []struct {
+ name string
+ attachID int64
+ expectedRepo *Repository
+ expectedUnitType UnitType
+ }{
+ {"LinkedIssue", 1, &Repository{ID: 1}, UnitTypeIssues},
+ {"LinkedComment", 3, &Repository{ID: 1}, UnitTypeIssues},
+ {"LinkedRelease", 9, &Repository{ID: 1}, UnitTypeReleases},
+ {"Notlinked", 10, nil, -1},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ attach, err := GetAttachmentByID(tc.attachID)
+ assert.NoError(t, err)
+ repo, unitType, err := attach.LinkedRepository()
+ assert.NoError(t, err)
+ if tc.expectedRepo != nil {
+ assert.Equal(t, tc.expectedRepo.ID, repo.ID)
+ }
+ assert.Equal(t, tc.expectedUnitType, unitType)
+
+ })
+ }
+}