1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

storage: Add Seen flag, tests for #58

This commit is contained in:
James Hillyerd
2018-03-31 21:46:10 -07:00
parent e3be5362dc
commit cc5cd7f9c3
8 changed files with 100 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ func StoreSuite(t *testing.T, factory StoreFactory) {
{"content", testContent, config.Storage{}},
{"delivery order", testDeliveryOrder, config.Storage{}},
{"size", testSize, config.Storage{}},
{"seen", testSeen, config.Storage{}},
{"delete", testDelete, config.Storage{}},
{"purge", testPurge, config.Storage{}},
{"cap=10", testMsgCap, config.Storage{MailboxMsgCap: 10}},
@@ -65,6 +66,7 @@ func testMetadata(t *testing.T, store storage.Store) {
To: to,
Date: date,
Subject: subject,
Seen: false,
},
Reader: strings.NewReader(content),
}
@@ -107,6 +109,9 @@ func testMetadata(t *testing.T, store storage.Store) {
if sm.Size() != int64(len(content)) {
t.Errorf("got size %v, want: %v", sm.Size(), len(content))
}
if sm.Seen() {
t.Errorf("got seen %v, want: false", sm.Seen())
}
}
// testContent generates some binary content and makes sure it is correctly retrieved.
@@ -210,6 +215,42 @@ func testSize(t *testing.T, store storage.Store) {
}
}
// testSeen verifies a message can be marked as seen.
func testSeen(t *testing.T, store storage.Store) {
mailbox := "lisa"
id1, _ := DeliverToStore(t, store, mailbox, "whatever", time.Now())
id2, _ := DeliverToStore(t, store, mailbox, "hello?", time.Now())
// Confirm unseen.
msg, err := store.GetMessage(mailbox, id1)
if err != nil {
t.Fatal(err)
}
if msg.Seen() {
t.Errorf("got seen %v, want: false", msg.Seen())
}
// Mark id1 seen.
err = store.MarkSeen(mailbox, id1)
if err != nil {
t.Fatal(err)
}
// Verify id1 seen.
msg, err = store.GetMessage(mailbox, id1)
if err != nil {
t.Fatal(err)
}
if !msg.Seen() {
t.Errorf("id1 got seen %v, want: true", msg.Seen())
}
// Verify id2 still unseen.
msg, err = store.GetMessage(mailbox, id2)
if err != nil {
t.Fatal(err)
}
if msg.Seen() {
t.Errorf("id2 got seen %v, want: false", msg.Seen())
}
}
// testDelete creates and deletes some messages.
func testDelete(t *testing.T, store storage.Store) {
mailbox := "fred"