@@ -8,23 +8,19 @@ import (
88 "path/filepath"
99 "strings"
1010 "testing"
11- "time"
1211
12+ _ "code.gitea.io/gitea/models/actions"
1313 "code.gitea.io/gitea/models/db"
1414 repo_model "code.gitea.io/gitea/models/repo"
15+ "code.gitea.io/gitea/models/system"
1516 "code.gitea.io/gitea/models/unittest"
1617 user_model "code.gitea.io/gitea/models/user"
1718 "code.gitea.io/gitea/modules/storage"
18-
19- _ "code.gitea.io/gitea/models/actions"
19+ storage_service "code.gitea.io/gitea/services/storage"
2020
2121 "github.com/stretchr/testify/assert"
2222)
2323
24- func TestMain (m * testing.M ) {
25- unittest .MainTest (m )
26- }
27-
2824func TestUploadAttachment (t * testing.T ) {
2925 assert .NoError (t , unittest .PrepareTestDatabase ())
3026
@@ -59,16 +55,28 @@ func TestDeleteAttachments(t *testing.T) {
5955 assert .NoError (t , err )
6056 assert .Equal (t , attachment8 .Size , fileInfo .Size ())
6157
62- err = DeleteAttachment (db .DefaultContext , attachment8 )
58+ deletionsTotal , err := db .Count [system.StoragePathDeletion ](t .Context (), db .ListOptionsAll )
59+ assert .NoError (t , err )
60+ assert .Equal (t , int64 (1 ), deletionsTotal )
61+
62+ err = DeleteAttachment (t .Context (), attachment8 )
6363 assert .NoError (t , err )
6464
65- attachment , err := repo_model .GetAttachmentByUUID (db . DefaultContext , attachment8 .UUID )
65+ attachment , err := repo_model .GetAttachmentByUUID (t . Context () , attachment8 .UUID )
6666 assert .Error (t , err )
6767 assert .True (t , repo_model .IsErrAttachmentNotExist (err ))
6868 assert .Nil (t , attachment )
6969
70- // allow the queue to process the deletion
71- time .Sleep (1 * time .Second )
70+ deletions , err := db .Find [system.StoragePathDeletion ](t .Context (), db .ListOptionsAll )
71+ assert .NoError (t , err )
72+ assert .Len (t , deletions , int (deletionsTotal )+ 1 )
73+ assert .Equal (t , attachment8 .RelativePath (), deletions [deletionsTotal ].RelativePath )
74+
75+ _ , err = storage .Attachments .Stat (attachment8 .RelativePath ())
76+ assert .NoError (t , err )
77+
78+ err = storage_service .ScanToBeDeletedFilesOrDir (t .Context ())
79+ assert .NoError (t , err )
7280
7381 _ , err = storage .Attachments .Stat (attachment8 .RelativePath ())
7482 assert .Error (t , err )
0 commit comments