From bf0b63db74108f61da2e305c3cec99d68cc804fe Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 15 Jan 2019 22:55:08 +0700 Subject: lib/smtp: add unit test for NewClient --- lib/smtp/client_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/smtp/client_test.go b/lib/smtp/client_test.go index 43e03f5c..22e68633 100644 --- a/lib/smtp/client_test.go +++ b/lib/smtp/client_test.go @@ -13,6 +13,31 @@ import ( "github.com/shuLhan/share/lib/test" ) +func TestNewClient(t *testing.T) { + cases := []struct { + desc string + raddr string + expErr string + }{{ + desc: "With invalid IP", + raddr: "!", + expErr: "lookup !: no such host", + }, { + desc: "With no MX", + raddr: "example.com", + expErr: "", + }} + + for _, c := range cases { + t.Log(c.desc) + + _, err := NewClient(c.raddr) + if err != nil { + test.Assert(t, "error", c.expErr, err.Error(), true) + } + } +} + func TestConnect(t *testing.T) { time.Sleep(1 * time.Second) -- cgit v1.3