This repository has been archived by the owner on Sep 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathemail_test.go
83 lines (67 loc) · 2.13 KB
/
email_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
package email
import (
"net/mail"
"strings"
"testing"
)
func TestAttachment(t *testing.T) {
m := NewMessage("Hi", "this is the body")
if err := m.AttachBuffer("test.ics", []byte("test"), false); err != nil {
t.Fatal(err)
}
if strings.Contains(string(m.Bytes()), "text/calendar") == false {
t.Fatal("Issue with mailer")
}
}
func TestHeaders(t *testing.T) {
m := NewMessage("Hi", "this is the body")
m.AddHeader("X-HEADER-KEY", "HEADERVAL")
if strings.Contains(string(m.Bytes()), "X-HEADER-KEY: HEADERVAL\r\n") == false {
t.Fatal("Could not find header in message")
}
}
func TestAddTo(t *testing.T) {
m := NewMessage("Hi", "this is the body")
names := []string{"firstName", "secondName"}
addresses := []string{"firstAddress", "secondAddress"}
firstAddress := mail.Address{Name: names[0], Address: addresses[0]}
m.AddTo(firstAddress)
if m.To[0] != firstAddress.String() {
t.Fatal("Incorrect first element")
}
secondAddress := mail.Address{Name: names[1], Address: addresses[1]}
m.AddTo(secondAddress)
if m.To[1] != secondAddress.String() {
t.Fatal("Incorrect second element")
}
}
func TestAddCc(t *testing.T) {
m := NewMessage("Hi", "this is the body")
names := []string{"firstName", "secondName"}
addresses := []string{"firstAddress", "secondAddress"}
firstAddress := mail.Address{Name: names[0], Address: addresses[0]}
m.AddCc(firstAddress)
if m.Cc[0] != firstAddress.String() {
t.Fatal("Incorrect first element")
}
secondAddress := mail.Address{Name: names[1], Address: addresses[1]}
m.AddCc(secondAddress)
if m.Cc[1] != secondAddress.String() {
t.Fatal("Incorrect second element")
}
}
func TestAddBcc(t *testing.T) {
m := NewMessage("Hi", "this is the body")
names := []string{"firstName", "secondName"}
addresses := []string{"firstAddress", "secondAddress"}
firstAddress := mail.Address{Name: names[0], Address: addresses[0]}
m.AddBcc(firstAddress)
if m.Bcc[0] != firstAddress.String() {
t.Fatal("Incorrect first element")
}
secondAddress := mail.Address{Name: names[1], Address: addresses[1]}
m.AddBcc(secondAddress)
if m.Bcc[1] != secondAddress.String() {
t.Fatal("Incorrect second element")
}
}