-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_test.go
87 lines (85 loc) · 2.26 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package mailing
import (
"net/mail"
"strings"
"testing"
)
func TestBuild(t *testing.T) {
m := newMessageBuilder()
m.setFrom(mail.Address{
Name: "from test name",
Address: "[email protected]",
})
m.setToList([]mail.Address{
{
Name: "to test name1",
Address: "[email protected]",
},
{
Name: "to test name2",
Address: "[email protected]",
},
})
m.setCCList([]mail.Address{
{
Name: "tcc test name1",
Address: "[email protected]",
},
{
Name: "cc test name2",
Address: "[email protected]",
},
})
m.setSubject("the subject")
m.setHTMLBody("this is html body")
m.setAttachments([]Attachment{
{
Name: "attachment name1",
Path: "./testingdata/attachment1.md",
},
{
Name: "attachment name2",
Path: "./testingdata/attachment2.md",
},
})
message := string(m.build())
if !strings.Contains(message, `From: "from test name" <[email protected]>`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `To: "to test name1" <[email protected]>;"to test name2" <[email protected]>`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `Cc: "tcc test name1" <[email protected]>;"cc test name2" <[email protected]>`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `Subject: the subject`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `Content-Type: text/html; charset="UTF-8"`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `this is html body`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `Content-Disposition: attachment; filename="attachment name1"`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `dGhpcyBpcyBhIHRlc3QgZmlsZSBmb3IgZW1haWwgYXR0YWNobWVudCAx`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `Content-Disposition: attachment; filename="attachment name2"`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `dGhpcyBpcyBhIHRlc3QgZmlsZSBmb3IgZW1haWwgYXR0YWNobWVudCAy`) {
t.Error("Failed test build")
}
m.setHTMLBody("")
m.setPlainTextBody("this is plain text body")
message = string(m.build())
if !strings.Contains(message, `Content-Type: text/plain; charset="UTF-8"`) {
t.Error("Failed test build")
}
if !strings.Contains(message, `this is plain text body`) {
t.Error("Failed test build")
}
}