@@ -6,13 +6,16 @@ package attachment
66import  (
77	"os" 
88	"path/filepath" 
9+ 	"strings" 
910	"testing" 
11+ 	"time" 
1012
1113	"code.gitea.io/gitea/models/db" 
1214	repo_model "code.gitea.io/gitea/models/repo" 
1315	"code.gitea.io/gitea/models/unittest" 
1416	user_model "code.gitea.io/gitea/models/user" 
1517	"code.gitea.io/gitea/modules/setting" 
18+ 	"code.gitea.io/gitea/modules/storage" 
1619	"code.gitea.io/gitea/services/storagecleanup" 
1720
1821	_ "code.gitea.io/gitea/models/actions" 
@@ -55,12 +58,26 @@ func TestUploadAttachment(t *testing.T) {
5558func  TestDeleteAttachments (t  * testing.T ) {
5659	assert .NoError (t , unittest .PrepareTestDatabase ())
5760	attachment8  :=  unittest .AssertExistsAndLoadBean (t , & repo_model.Attachment {ID : 8 })
61+ 	const  attachment8Content  =  "test content for attachment 8"  // 29 bytes 
62+ 	_ , err  :=  storage .Attachments .Save (attachment8 .RelativePath (), strings .NewReader (attachment8Content ), int64 (len (attachment8Content )))
63+ 	assert .NoError (t , err )
64+ 
65+ 	fileInfo , err  :=  storage .Attachments .Stat (attachment8 .RelativePath ())
66+ 	assert .NoError (t , err )
67+ 	assert .Equal (t , attachment8 .Size , fileInfo .Size ())
5868
59- 	err  : =  DeleteAttachment (db .DefaultContext , attachment8 )
69+ 	err  =  DeleteAttachment (db .DefaultContext , attachment8 )
6070	assert .NoError (t , err )
6171
62- 	attachment , err  :=  repo_model .GetAttachmentByUUID (db .DefaultContext , "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18" )
72+ 	attachment , err  :=  repo_model .GetAttachmentByUUID (db .DefaultContext , attachment8 . UUID )
6373	assert .Error (t , err )
6474	assert .True (t , repo_model .IsErrAttachmentNotExist (err ))
6575	assert .Nil (t , attachment )
76+ 
77+ 	// allow the queue to process the deletion 
78+ 	time .Sleep (1  *  time .Second )
79+ 
80+ 	_ , err  =  storage .Attachments .Stat (attachment8 .RelativePath ())
81+ 	assert .Error (t , err )
82+ 	assert .True (t , os .IsNotExist (err ))
6683}
0 commit comments