summaryrefslogtreecommitdiffstats
path: root/utils/mail_test.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-01-24 16:25:41 +0100
committerCorey Hulen <corey@hulen.com>2017-01-24 10:25:41 -0500
commit3234f98aec24c4f0f04fa6d083678afbf793b9d2 (patch)
tree82d9eb3ff044a72f11f583c2fd255b4742f8fc86 /utils/mail_test.go
parent479bd1a2b307a1fc35b7ca5869166875612c62b1 (diff)
downloadchat-3234f98aec24c4f0f04fa6d083678afbf793b9d2.tar.gz
chat-3234f98aec24c4f0f04fa6d083678afbf793b9d2.tar.bz2
chat-3234f98aec24c4f0f04fa6d083678afbf793b9d2.zip
add initial tests for utils/mail.go (#5176)
Diffstat (limited to 'utils/mail_test.go')
-rw-r--r--utils/mail_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/utils/mail_test.go b/utils/mail_test.go
new file mode 100644
index 000000000..012f10d39
--- /dev/null
+++ b/utils/mail_test.go
@@ -0,0 +1,61 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package utils
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestMailConnection(t *testing.T) {
+ LoadConfig("config.json")
+
+ if conn, err := connectToSMTPServer(Cfg); err != nil {
+ t.Log(err)
+ t.Fatal("Should connect to the STMP Server")
+ } else {
+ if _, err1 := newSMTPClient(conn, Cfg); err1 != nil {
+ t.Log(err)
+ t.Fatal("Should get new smtp client")
+ }
+ }
+
+ Cfg.EmailSettings.SMTPServer = "wrongServer"
+ Cfg.EmailSettings.SMTPPort = "553"
+
+ if _, err := connectToSMTPServer(Cfg); err == nil {
+ t.Log(err)
+ t.Fatal("Should not to the STMP Server")
+ }
+
+}
+
+func TestSendMail(t *testing.T) {
+ LoadConfig("config.json")
+ T = GetUserTranslations("en")
+
+ var emailTo string = "test@example.com"
+ var emailSubject string = "Testing this email"
+ var emailBody string = "This is a test from autobot"
+
+ //Delete all the messages before check the sample email
+ DeleteMailBox(emailTo)
+
+ if err := SendMail(emailTo, emailSubject, emailBody); err != nil {
+ t.Log(err)
+ t.Fatal("Should connect to the STMP Server")
+ } else {
+ //Check if the email was send to the rigth email address
+ if resultsMailbox, err := GetMailBox(emailTo); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
+ t.Fatal("Wrong To recipient")
+ } else {
+ if resultsEmail, err := GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
+ if !strings.Contains(resultsEmail.Body.Text, emailBody) {
+ t.Log(resultsEmail.Body.Text)
+ t.Fatal("Received message")
+ }
+ }
+ }
+ }
+}