test: cover reconciliation dry runs

This commit is contained in:
2026-10-30 14:08:14 +03:00
parent f8a624a40b
commit 4e1a74d9ff
@@ -18,6 +18,7 @@ import (
"gitea.privcloud.tech/dizi/mtusi2026lab5/internal/database"
"gitea.privcloud.tech/dizi/mtusi2026lab5/internal/model"
"gitea.privcloud.tech/dizi/mtusi2026lab5/internal/postgres"
"gitea.privcloud.tech/dizi/mtusi2026lab5/internal/reconcile"
)
type PostgresSuite struct {
@@ -412,6 +413,43 @@ func (s *PostgresSuite) TestAttachmentDeletionClaimChecksLifecycleUnderLock() {
s.Equal(model.AttachmentReady, visible.Status)
}
func (s *PostgresSuite) TestReconciliationDryRunPreservesDeletingAttachment() {
owner, chatID := createOwnerAndChat(s.T(), s.store)
pending, err := s.store.CreatePendingAttachment(context.Background(), model.Attachment{
ID: uuid.NewString(), ChatID: chatID, OwnerID: owner.ID, Filename: "deleting.png",
ContentType: "image/png", SizeBytes: 128, SHA256: strings.Repeat("e", 64),
ObjectKey: "attachments/" + uuid.NewString() + "/original",
})
s.Require().NoError(err)
claimed, err := s.store.ClaimAttachmentForDeletion(context.Background(), pending, time.Now().Add(time.Hour))
s.Require().NoError(err)
s.True(claimed)
reconciler, err := reconcile.New(s.store, emptyObjectStore{}, reconcile.Config{
Prefix: "attachments/", PageSize: 1000, GraceTime: time.Minute,
UnreferencedRetention: time.Hour,
})
s.Require().NoError(err)
report, err := reconciler.Run(context.Background())
s.Require().NoError(err)
s.Zero(report.DeletedUnreferencedRows)
var status string
err = s.pool.QueryRow(context.Background(), "SELECT status FROM attachments WHERE id = $1", pending.ID).Scan(&status)
s.Require().NoError(err)
s.Equal(model.AttachmentDeleting, status)
}
type emptyObjectStore struct{}
func (emptyObjectStore) List(context.Context, string, string, int) ([]model.StoredObject, string, error) {
return nil, "", nil
}
func (emptyObjectStore) Delete(context.Context, string) error {
return errors.New("unexpected object deletion")
}
func (s *PostgresSuite) TestMessageRejectsAttachmentFromAnotherChat() {
owner, firstChatID := createOwnerAndChat(s.T(), s.store)
secondChat, err := s.store.CreateChat(context.Background(), "Second", []string{owner.ID}, owner.ID)