From 6fb106b618519845da4435edba3c1b1598333ffd Mon Sep 17 00:00:00 2001
From: LetMyPplGo <54865472+LetMyPplGo@users.noreply.github.com>
Date: Tue, 17 Sep 2019 00:06:46 +0300
Subject: [PATCH] added tests for gsmtp
---
net/gsmtp/gsmtp_test.go | 77 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 net/gsmtp/gsmtp_test.go
diff --git a/net/gsmtp/gsmtp_test.go b/net/gsmtp/gsmtp_test.go
new file mode 100644
index 000000000..fcd15350c
--- /dev/null
+++ b/net/gsmtp/gsmtp_test.go
@@ -0,0 +1,77 @@
+// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
+//
+// This Source Code Form is subject to the terms of the MIT License.
+// If a copy of the MIT was not distributed with this file,
+// You can obtain one at https://github.com/gogf/gf.
+package gsmtp_test
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/gogf/gf/net/gsmtp"
+)
+
+func TestAddress(t *testing.T) {
+ errMessage := "address is either empty or incorrect"
+
+ errValues := []string{
+ "",
+ ":",
+ ":25",
+ "localhost:",
+ "local.host:25:28",
+ }
+
+ for _, errValue := range errValues {
+ smtpConnection := gsmtp.New(errValue, "smtpUser@smtp.exmail.qq.com", "smtpPassword")
+ res := smtpConnection.SendMail("sender@local.host", "recipient1@domain.com;recipientN@anotherDomain.cn", "This is subject", "Hi!
This is body")
+ if !strings.Contains(res.Error(), errMessage) {
+ t.Errorf("Test failed on Address: %s", errValue)
+ }
+ }
+}
+
+func TestFrom(t *testing.T) {
+ errMessage := "from is invalid"
+
+ errValues := []string{
+ "",
+ "qwerty",
+ // "qwe@rty@com",
+ // "@rty",
+ // "qwe@",
+ }
+
+ for _, errValue := range errValues {
+ smtpConnection := gsmtp.New("smtp.exmail.qq.com", "smtpUser@smtp.exmail.qq.com", "smtpPassword")
+ res := smtpConnection.SendMail(errValue, "recipient1@domain.com;recipientN@anotherDomain.cn", "This is subject", "Hi!
This is body")
+ if !strings.Contains(res.Error(), errMessage) {
+ t.Errorf("Test failed on From: %s", errValue)
+ }
+ }
+
+}
+
+func TestTos(t *testing.T) {
+ errMessage := "tos if invalid"
+
+ errValues := []string{
+ "",
+ "qwerty",
+ "qwe;rty",
+ "qwe;rty;com",
+ // "qwe@rty@com",
+ // "@rty",
+ // "qwe@",
+ }
+
+ for _, errValue := range errValues {
+ smtpConnection := gsmtp.New("smtp.exmail.qq.com", "smtpUser@smtp.exmail.qq.com", "smtpPassword")
+ res := smtpConnection.SendMail("from@domain.com", errValue, "This is subject", "Hi!
This is body")
+ if !strings.Contains(res.Error(), errMessage) {
+ t.Errorf("Test failed on Tos: %s", errValue)
+ }
+ }
+
+}