-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
375 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ package storage | |
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/axllent/mailpit/config" | ||
) | ||
|
||
func TestTextEmailInserts(t *testing.T) { | ||
setup() | ||
setup("") | ||
defer Close() | ||
|
||
t.Log("Testing text email storage") | ||
|
@@ -38,113 +40,140 @@ func TestTextEmailInserts(t *testing.T) { | |
} | ||
|
||
func TestMimeEmailInserts(t *testing.T) { | ||
setup() | ||
defer Close() | ||
for _, tenantID := range []string{"", "MyServer 3", "host.example.com"} { | ||
tenantID = config.DBTenantID(tenantID) | ||
|
||
t.Log("Testing mime email storage") | ||
setup(tenantID) | ||
|
||
start := time.Now() | ||
if tenantID == "" { | ||
t.Log("Testing mime email storage") | ||
} else { | ||
t.Logf("Testing mime email storage (tenant %s)", tenantID) | ||
} | ||
|
||
for i := 0; i < testRuns; i++ { | ||
if _, err := Store(&testMimeEmail); err != nil { | ||
start := time.Now() | ||
|
||
for i := 0; i < testRuns; i++ { | ||
if _, err := Store(&testMimeEmail); err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
} | ||
|
||
assertEqual(t, CountTotal(), float64(testRuns), "Incorrect number of mime emails stored") | ||
|
||
t.Logf("Inserted %d text emails in %s", testRuns, time.Since(start)) | ||
|
||
delStart := time.Now() | ||
if err := DeleteAllMessages(); err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
} | ||
|
||
assertEqual(t, CountTotal(), float64(testRuns), "Incorrect number of mime emails stored") | ||
assertEqual(t, CountTotal(), float64(0), "incorrect number of mime emails deleted") | ||
|
||
t.Logf("Inserted %d text emails in %s", testRuns, time.Since(start)) | ||
t.Logf("Deleted %d mime emails in %s", testRuns, time.Since(delStart)) | ||
|
||
delStart := time.Now() | ||
if err := DeleteAllMessages(); err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
Close() | ||
} | ||
|
||
assertEqual(t, CountTotal(), float64(0), "incorrect number of mime emails deleted") | ||
|
||
t.Logf("Deleted %d mime emails in %s", testRuns, time.Since(delStart)) | ||
} | ||
|
||
func TestRetrieveMimeEmail(t *testing.T) { | ||
setup() | ||
defer Close() | ||
for _, tenantID := range []string{"", "MyServer 3", "host.example.com"} { | ||
tenantID = config.DBTenantID(tenantID) | ||
|
||
t.Log("Testing mime email retrieval") | ||
setup(tenantID) | ||
|
||
id, err := Store(&testMimeEmail) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
if tenantID == "" { | ||
t.Log("Testing mime email retrieval") | ||
} else { | ||
t.Logf("Testing mime email retrieval (tenant %s)", tenantID) | ||
} | ||
|
||
msg, err := GetMessage(id) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
id, err := Store(&testMimeEmail) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
|
||
assertEqual(t, msg.From.Name, "Sender Smith", "\"From\" name does not match") | ||
assertEqual(t, msg.From.Address, "[email protected]", "\"From\" address does not match") | ||
assertEqual(t, msg.Subject, "inline + attachment", "subject does not match") | ||
assertEqual(t, len(msg.To), 1, "incorrect number of recipients") | ||
assertEqual(t, msg.To[0].Name, "Recipient Ross", "\"To\" name does not match") | ||
assertEqual(t, msg.To[0].Address, "[email protected]", "\"To\" address does not match") | ||
assertEqual(t, len(msg.Attachments), 1, "incorrect number of attachments") | ||
assertEqual(t, msg.Attachments[0].FileName, "Sample PDF.pdf", "attachment filename does not match") | ||
assertEqual(t, len(msg.Inline), 1, "incorrect number of inline attachments") | ||
assertEqual(t, msg.Inline[0].FileName, "inline-image.jpg", "inline attachment filename does not match") | ||
|
||
attachmentData, err := GetAttachmentPart(id, msg.Attachments[0].PartID) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
assertEqual(t, float64(len(attachmentData.Content)), msg.Attachments[0].Size, "attachment size does not match") | ||
msg, err := GetMessage(id) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
|
||
inlineData, err := GetAttachmentPart(id, msg.Inline[0].PartID) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
assertEqual(t, msg.From.Name, "Sender Smith", "\"From\" name does not match") | ||
assertEqual(t, msg.From.Address, "[email protected]", "\"From\" address does not match") | ||
assertEqual(t, msg.Subject, "inline + attachment", "subject does not match") | ||
assertEqual(t, len(msg.To), 1, "incorrect number of recipients") | ||
assertEqual(t, msg.To[0].Name, "Recipient Ross", "\"To\" name does not match") | ||
assertEqual(t, msg.To[0].Address, "[email protected]", "\"To\" address does not match") | ||
assertEqual(t, len(msg.Attachments), 1, "incorrect number of attachments") | ||
assertEqual(t, msg.Attachments[0].FileName, "Sample PDF.pdf", "attachment filename does not match") | ||
assertEqual(t, len(msg.Inline), 1, "incorrect number of inline attachments") | ||
assertEqual(t, msg.Inline[0].FileName, "inline-image.jpg", "inline attachment filename does not match") | ||
|
||
attachmentData, err := GetAttachmentPart(id, msg.Attachments[0].PartID) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
assertEqual(t, float64(len(attachmentData.Content)), msg.Attachments[0].Size, "attachment size does not match") | ||
|
||
inlineData, err := GetAttachmentPart(id, msg.Inline[0].PartID) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
assertEqual(t, float64(len(inlineData.Content)), msg.Inline[0].Size, "inline attachment size does not match") | ||
|
||
Close() | ||
} | ||
assertEqual(t, float64(len(inlineData.Content)), msg.Inline[0].Size, "inline attachment size does not match") | ||
} | ||
|
||
func TestMessageSummary(t *testing.T) { | ||
setup() | ||
defer Close() | ||
for _, tenantID := range []string{"", "MyServer 3", "host.example.com"} { | ||
tenantID = config.DBTenantID(tenantID) | ||
|
||
t.Log("Testing message summary") | ||
setup(tenantID) | ||
|
||
if _, err := Store(&testMimeEmail); err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
if tenantID == "" { | ||
t.Log("Testing message summary") | ||
} else { | ||
t.Logf("Testing message summary (tenant %s)", tenantID) | ||
} | ||
|
||
summaries, err := List(0, 0, 1) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
if _, err := Store(&testMimeEmail); err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
|
||
summaries, err := List(0, 0, 1) | ||
if err != nil { | ||
t.Log("error ", err) | ||
t.Fail() | ||
} | ||
|
||
assertEqual(t, len(summaries), 1, "Expected 1 result") | ||
assertEqual(t, len(summaries), 1, "Expected 1 result") | ||
|
||
msg := summaries[0] | ||
msg := summaries[0] | ||
|
||
assertEqual(t, msg.From.Name, "Sender Smith", "\"From\" name does not match") | ||
assertEqual(t, msg.From.Address, "[email protected]", "\"From\" address does not match") | ||
assertEqual(t, msg.Subject, "inline + attachment", "subject does not match") | ||
assertEqual(t, len(msg.To), 1, "incorrect number of recipients") | ||
assertEqual(t, msg.To[0].Name, "Recipient Ross", "\"To\" name does not match") | ||
assertEqual(t, msg.To[0].Address, "[email protected]", "\"To\" address does not match") | ||
assertEqual(t, msg.Snippet, "Message with inline image and attachment:", "\"Snippet\" does does not match") | ||
assertEqual(t, msg.Attachments, 1, "Expected 1 attachment") | ||
assertEqual(t, msg.MessageID, "[email protected]", "\"MessageID\" does not match") | ||
assertEqual(t, msg.From.Name, "Sender Smith", "\"From\" name does not match") | ||
assertEqual(t, msg.From.Address, "[email protected]", "\"From\" address does not match") | ||
assertEqual(t, msg.Subject, "inline + attachment", "subject does not match") | ||
assertEqual(t, len(msg.To), 1, "incorrect number of recipients") | ||
assertEqual(t, msg.To[0].Name, "Recipient Ross", "\"To\" name does not match") | ||
assertEqual(t, msg.To[0].Address, "[email protected]", "\"To\" address does not match") | ||
assertEqual(t, msg.Snippet, "Message with inline image and attachment:", "\"Snippet\" does does not match") | ||
assertEqual(t, msg.Attachments, 1, "Expected 1 attachment") | ||
assertEqual(t, msg.MessageID, "[email protected]", "\"MessageID\" does not match") | ||
|
||
Close() | ||
} | ||
} | ||
|
||
func BenchmarkImportText(b *testing.B) { | ||
setup() | ||
setup("") | ||
defer Close() | ||
|
||
for i := 0; i < b.N; i++ { | ||
|
@@ -156,7 +185,7 @@ func BenchmarkImportText(b *testing.B) { | |
} | ||
|
||
func BenchmarkImportMime(b *testing.B) { | ||
setup() | ||
setup("") | ||
defer Close() | ||
|
||
for i := 0; i < b.N; i++ { | ||
|
Oops, something went wrong.