@@ -3,10 +3,12 @@ package storage
3
3
import (
4
4
"testing"
5
5
"time"
6
+
7
+ "github.com/axllent/mailpit/config"
6
8
)
7
9
8
10
func TestTextEmailInserts (t * testing.T ) {
9
- setup ()
11
+ setup ("" )
10
12
defer Close ()
11
13
12
14
t .Log ("Testing text email storage" )
@@ -38,113 +40,140 @@ func TestTextEmailInserts(t *testing.T) {
38
40
}
39
41
40
42
func TestMimeEmailInserts (t * testing.T ) {
41
- setup ()
42
- defer Close ( )
43
+ for _ , tenantID := range [] string { "" , "MyServer 3" , "host.example.com" } {
44
+ tenantID = config . DBTenantID ( tenantID )
43
45
44
- t . Log ( "Testing mime email storage" )
46
+ setup ( tenantID )
45
47
46
- start := time .Now ()
48
+ if tenantID == "" {
49
+ t .Log ("Testing mime email storage" )
50
+ } else {
51
+ t .Logf ("Testing mime email storage (tenant %s)" , tenantID )
52
+ }
47
53
48
- for i := 0 ; i < testRuns ; i ++ {
49
- if _ , err := Store (& testMimeEmail ); err != nil {
54
+ start := time .Now ()
55
+
56
+ for i := 0 ; i < testRuns ; i ++ {
57
+ if _ , err := Store (& testMimeEmail ); err != nil {
58
+ t .Log ("error " , err )
59
+ t .Fail ()
60
+ }
61
+ }
62
+
63
+ assertEqual (t , CountTotal (), float64 (testRuns ), "Incorrect number of mime emails stored" )
64
+
65
+ t .Logf ("Inserted %d text emails in %s" , testRuns , time .Since (start ))
66
+
67
+ delStart := time .Now ()
68
+ if err := DeleteAllMessages (); err != nil {
50
69
t .Log ("error " , err )
51
70
t .Fail ()
52
71
}
53
- }
54
72
55
- assertEqual (t , CountTotal (), float64 (testRuns ), "Incorrect number of mime emails stored " )
73
+ assertEqual (t , CountTotal (), float64 (0 ), "incorrect number of mime emails deleted " )
56
74
57
- t .Logf ("Inserted %d text emails in %s" , testRuns , time .Since (start ))
75
+ t .Logf ("Deleted %d mime emails in %s" , testRuns , time .Since (delStart ))
58
76
59
- delStart := time .Now ()
60
- if err := DeleteAllMessages (); err != nil {
61
- t .Log ("error " , err )
62
- t .Fail ()
77
+ Close ()
63
78
}
64
-
65
- assertEqual (t , CountTotal (), float64 (0 ), "incorrect number of mime emails deleted" )
66
-
67
- t .Logf ("Deleted %d mime emails in %s" , testRuns , time .Since (delStart ))
68
79
}
69
80
70
81
func TestRetrieveMimeEmail (t * testing.T ) {
71
- setup ()
72
- defer Close ( )
82
+ for _ , tenantID := range [] string { "" , "MyServer 3" , "host.example.com" } {
83
+ tenantID = config . DBTenantID ( tenantID )
73
84
74
- t . Log ( "Testing mime email retrieval" )
85
+ setup ( tenantID )
75
86
76
- id , err := Store ( & testMimeEmail )
77
- if err != nil {
78
- t . Log ( "error " , err )
79
- t . Fail ( )
80
- }
87
+ if tenantID == "" {
88
+ t . Log ( "Testing mime email retrieval" )
89
+ } else {
90
+ t . Logf ( "Testing mime email retrieval (tenant %s)" , tenantID )
91
+ }
81
92
82
- msg , err := GetMessage ( id )
83
- if err != nil {
84
- t .Log ("error " , err )
85
- t .Fail ()
86
- }
93
+ id , err := Store ( & testMimeEmail )
94
+ if err != nil {
95
+ t .Log ("error " , err )
96
+ t .Fail ()
97
+ }
87
98
88
- assertEqual (t , msg .From .Name , "Sender Smith" , "\" From\" name does not match" )
89
- assertEqual (
t ,
msg .
From .
Address ,
"[email protected] " ,
"\" From\" address does not match" )
90
- assertEqual (t , msg .Subject , "inline + attachment" , "subject does not match" )
91
- assertEqual (t , len (msg .To ), 1 , "incorrect number of recipients" )
92
- assertEqual (t , msg .To [0 ].Name , "Recipient Ross" , "\" To\" name does not match" )
93
- assertEqual (
t ,
msg .
To [
0 ].
Address ,
"[email protected] " ,
"\" To\" address does not match" )
94
- assertEqual (t , len (msg .Attachments ), 1 , "incorrect number of attachments" )
95
- assertEqual (t , msg .Attachments [0 ].FileName , "Sample PDF.pdf" , "attachment filename does not match" )
96
- assertEqual (t , len (msg .Inline ), 1 , "incorrect number of inline attachments" )
97
- assertEqual (t , msg .Inline [0 ].FileName , "inline-image.jpg" , "inline attachment filename does not match" )
98
-
99
- attachmentData , err := GetAttachmentPart (id , msg .Attachments [0 ].PartID )
100
- if err != nil {
101
- t .Log ("error " , err )
102
- t .Fail ()
103
- }
104
- assertEqual (t , float64 (len (attachmentData .Content )), msg .Attachments [0 ].Size , "attachment size does not match" )
99
+ msg , err := GetMessage (id )
100
+ if err != nil {
101
+ t .Log ("error " , err )
102
+ t .Fail ()
103
+ }
105
104
106
- inlineData , err := GetAttachmentPart (id , msg .Inline [0 ].PartID )
107
- if err != nil {
108
- t .Log ("error " , err )
109
- t .Fail ()
105
+ assertEqual (t , msg .From .Name , "Sender Smith" , "\" From\" name does not match" )
106
+ assertEqual (
t ,
msg .
From .
Address ,
"[email protected] " ,
"\" From\" address does not match" )
107
+ assertEqual (t , msg .Subject , "inline + attachment" , "subject does not match" )
108
+ assertEqual (t , len (msg .To ), 1 , "incorrect number of recipients" )
109
+ assertEqual (t , msg .To [0 ].Name , "Recipient Ross" , "\" To\" name does not match" )
110
+ assertEqual (
t ,
msg .
To [
0 ].
Address ,
"[email protected] " ,
"\" To\" address does not match" )
111
+ assertEqual (t , len (msg .Attachments ), 1 , "incorrect number of attachments" )
112
+ assertEqual (t , msg .Attachments [0 ].FileName , "Sample PDF.pdf" , "attachment filename does not match" )
113
+ assertEqual (t , len (msg .Inline ), 1 , "incorrect number of inline attachments" )
114
+ assertEqual (t , msg .Inline [0 ].FileName , "inline-image.jpg" , "inline attachment filename does not match" )
115
+
116
+ attachmentData , err := GetAttachmentPart (id , msg .Attachments [0 ].PartID )
117
+ if err != nil {
118
+ t .Log ("error " , err )
119
+ t .Fail ()
120
+ }
121
+ assertEqual (t , float64 (len (attachmentData .Content )), msg .Attachments [0 ].Size , "attachment size does not match" )
122
+
123
+ inlineData , err := GetAttachmentPart (id , msg .Inline [0 ].PartID )
124
+ if err != nil {
125
+ t .Log ("error " , err )
126
+ t .Fail ()
127
+ }
128
+ assertEqual (t , float64 (len (inlineData .Content )), msg .Inline [0 ].Size , "inline attachment size does not match" )
129
+
130
+ Close ()
110
131
}
111
- assertEqual (t , float64 (len (inlineData .Content )), msg .Inline [0 ].Size , "inline attachment size does not match" )
112
132
}
113
133
114
134
func TestMessageSummary (t * testing.T ) {
115
- setup ()
116
- defer Close ( )
135
+ for _ , tenantID := range [] string { "" , "MyServer 3" , "host.example.com" } {
136
+ tenantID = config . DBTenantID ( tenantID )
117
137
118
- t . Log ( "Testing message summary" )
138
+ setup ( tenantID )
119
139
120
- if _ , err := Store (& testMimeEmail ); err != nil {
121
- t .Log ("error " , err )
122
- t .Fail ()
123
- }
140
+ if tenantID == "" {
141
+ t .Log ("Testing message summary" )
142
+ } else {
143
+ t .Logf ("Testing message summary (tenant %s)" , tenantID )
144
+ }
124
145
125
- summaries , err := List (0 , 0 , 1 )
126
- if err != nil {
127
- t .Log ("error " , err )
128
- t .Fail ()
129
- }
146
+ if _ , err := Store (& testMimeEmail ); err != nil {
147
+ t .Log ("error " , err )
148
+ t .Fail ()
149
+ }
150
+
151
+ summaries , err := List (0 , 0 , 1 )
152
+ if err != nil {
153
+ t .Log ("error " , err )
154
+ t .Fail ()
155
+ }
130
156
131
- assertEqual (t , len (summaries ), 1 , "Expected 1 result" )
157
+ assertEqual (t , len (summaries ), 1 , "Expected 1 result" )
132
158
133
- msg := summaries [0 ]
159
+ msg := summaries [0 ]
134
160
135
- assertEqual (t , msg .From .Name , "Sender Smith" , "\" From\" name does not match" )
136
- assertEqual (
t ,
msg .
From .
Address ,
"[email protected] " ,
"\" From\" address does not match" )
137
- assertEqual (t , msg .Subject , "inline + attachment" , "subject does not match" )
138
- assertEqual (t , len (msg .To ), 1 , "incorrect number of recipients" )
139
- assertEqual (t , msg .To [0 ].Name , "Recipient Ross" , "\" To\" name does not match" )
140
- assertEqual (
t ,
msg .
To [
0 ].
Address ,
"[email protected] " ,
"\" To\" address does not match" )
141
- assertEqual (t , msg .Snippet , "Message with inline image and attachment:" , "\" Snippet\" does does not match" )
142
- assertEqual (t , msg .Attachments , 1 , "Expected 1 attachment" )
143
- assertEqual (
t ,
msg .
MessageID ,
"[email protected] " ,
"\" MessageID\" does not match" )
161
+ assertEqual (t , msg .From .Name , "Sender Smith" , "\" From\" name does not match" )
162
+ assertEqual (
t ,
msg .
From .
Address ,
"[email protected] " ,
"\" From\" address does not match" )
163
+ assertEqual (t , msg .Subject , "inline + attachment" , "subject does not match" )
164
+ assertEqual (t , len (msg .To ), 1 , "incorrect number of recipients" )
165
+ assertEqual (t , msg .To [0 ].Name , "Recipient Ross" , "\" To\" name does not match" )
166
+ assertEqual (
t ,
msg .
To [
0 ].
Address ,
"[email protected] " ,
"\" To\" address does not match" )
167
+ assertEqual (t , msg .Snippet , "Message with inline image and attachment:" , "\" Snippet\" does does not match" )
168
+ assertEqual (t , msg .Attachments , 1 , "Expected 1 attachment" )
169
+ assertEqual (
t ,
msg .
MessageID ,
"[email protected] " ,
"\" MessageID\" does not match" )
170
+
171
+ Close ()
172
+ }
144
173
}
145
174
146
175
func BenchmarkImportText (b * testing.B ) {
147
- setup ()
176
+ setup ("" )
148
177
defer Close ()
149
178
150
179
for i := 0 ; i < b .N ; i ++ {
@@ -156,7 +185,7 @@ func BenchmarkImportText(b *testing.B) {
156
185
}
157
186
158
187
func BenchmarkImportMime (b * testing.B ) {
159
- setup ()
188
+ setup ("" )
160
189
defer Close ()
161
190
162
191
for i := 0 ; i < b .N ; i ++ {
0 commit comments