-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_handler_test.go
97 lines (84 loc) · 2.39 KB
/
mail_handler_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
88
89
90
91
92
93
94
95
96
97
package delayed_job
import (
"flag"
"testing"
)
var test_mail_to = flag.String("test.mail_to", "", "the address of mail")
func TestMailHandlerParameterIsError(t *testing.T) {
_, e := newMailHandler(nil, map[string]interface{}{})
if nil == e {
t.Error("excepted error is not nil, but actual is nil")
} else if "ctx is nil" != e.Error() {
t.Error("excepted error is 'ctx is nil', but actual is", e)
}
_, e = newMailHandler(map[string]interface{}{}, nil)
if nil == e {
t.Error("excepted error is not nil, but actual is nil")
} else if "params is nil" != e.Error() {
t.Error("excepted error is 'params is nil', but actual is", e)
}
_, e = newMailHandler(map[string]interface{}{}, map[string]interface{}{})
if nil == e {
t.Error("excepted error is not nil, but actual is nil")
} else if "'content' is required" != e.Error() {
t.Error("excepted error is ['content' is required.], but actual is", e)
}
}
func TestMailHandler(t *testing.T) {
if "" == *defaultSmtpServer {
t.Skip("please set 'test.mail_to', 'mail.from' and 'mail.smtp_server'")
return
}
handler, e := newMailHandler(map[string]interface{}{}, map[string]interface{}{"to_address": *test_mail_to, "subject": "this is test subject!", "content": `
this is a test mail!
`})
if nil != e {
t.Error(e)
return
}
e = handler.Perform()
if nil != e {
t.Error(e)
return
}
}
func TestMailHandlerWithArguments(t *testing.T) {
if "" == *defaultSmtpServer {
t.Skip("please set 'test.mail_to', 'mail.from' and 'mail.smtp_server'")
return
}
handler, e := newMailHandler(map[string]interface{}{}, map[string]interface{}{"arguments": map[string]interface{}{"client": "mei"},
"to_address": *test_mail_to, "subject": "this is test subject!", "content": `
{{.client}}, this is a test mail!
`})
if nil != e {
t.Error(e)
return
}
e = handler.Perform()
if nil != e {
t.Error(e)
return
}
}
func TestMailHandlerAttachments(t *testing.T) {
if "" == *defaultSmtpServer {
t.Skip("please set 'test.mail_to', 'mail.from' and 'mail.smtp_server'")
return
}
handler, e := newMailHandler(map[string]interface{}{}, map[string]interface{}{"to_address": *test_mail_to, "subject": "this is test subject!", "content": `
this is a test mail!
`,
"attachments": []interface{}{
map[string]interface{}{"file": ".travis.yml"},
}})
if nil != e {
t.Error(e)
return
}
e = handler.Perform()
if nil != e {
t.Error(e)
return
}
}