-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
config_test.go
92 lines (79 loc) · 2.92 KB
/
config_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
package gomail
import "testing"
// TestContainsServiceProvider will check the containsServiceProvider() method
func TestContainsServiceProvider(t *testing.T) {
t.Parallel()
// Create the list of tests
var tests = []struct {
providers []ServiceProvider
provider ServiceProvider
expected bool
}{
{[]ServiceProvider{AwsSes}, AwsSes, true},
{[]ServiceProvider{Mandrill, AwsSes, SMTP, Postmark}, AwsSes, true},
{[]ServiceProvider{Mandrill, AwsSes}, AwsSes, true},
{[]ServiceProvider{Mandrill}, AwsSes, false},
{[]ServiceProvider{SMTP}, AwsSes, false},
{[]ServiceProvider{}, AwsSes, false},
}
// Loop tests
for _, test := range tests {
if found := containsServiceProvider(test.providers, test.provider); found && !test.expected {
t.Fatalf("%s Failed: [%v] providers, [%d] provider, found but expected to fail", t.Name(), test.providers, test.provider)
} else if !found && test.expected {
t.Fatalf("%s Failed: [%v] providers, [%d] provider, NOT found but expected to succeed", t.Name(), test.providers, test.provider)
}
}
}
// TestMailService_StartUp will test the StartUp() method
func TestMailService_StartUp(t *testing.T) {
t.Parallel()
service := new(MailService)
err := service.StartUp()
// No username
if err == nil || err.Error() != "missing required field: from_username" {
t.Fatalf("%s Failed: expected an error for missing from name, error: %v", t.Name(), err)
}
// No domain
service.FromUsername = "someone"
err = service.StartUp()
if err == nil || err.Error() != "missing required field: from_domain" {
t.Fatalf("%s Failed: expected an error for missing from domain, error: %v", t.Name(), err)
}
// No providers
service.FromDomain = "example.com"
err = service.StartUp()
if err == nil || err.Error() != "attempted to startup the email service provider(s) however there's no available service provider" {
t.Fatalf("%s Failed: expected an error for missing a provider, error: %v", t.Name(), err)
}
// Add Mandrill api key
service.MandrillAPIKey = "1234567"
err = service.StartUp()
if err != nil {
t.Fatalf("%s Failed: error should not have occurred, error: %s", t.Name(), err.Error())
}
// Add AWS credentials
service.AwsSesAccessID = "1234567"
service.AwsSesSecretKey = "1234567"
service.AwsSesEndpoint = awsSesDefaultEndpoint
service.AwsSesRegion = awsSesDefaultRegion
err = service.StartUp()
if err != nil {
t.Fatalf("%s Failed: error should not have occurred, error: %s", t.Name(), err.Error())
}
// Add postmark credentials
service.PostmarkServerToken = "1234567"
err = service.StartUp()
if err != nil {
t.Fatalf("%s Failed: error should not have occurred, error: %s", t.Name(), err.Error())
}
// Add SMTP
service.SMTPHost = "example.com"
service.SMTPPassword = "fake-password"
service.SMTPUsername = "fake-username"
service.SMTPPort = 25
err = service.StartUp()
if err != nil {
t.Fatalf("%s Failed: error should not have occurred, error: %s", t.Name(), err.Error())
}
}