diff --git a/msg_nowin_test.go b/msg_nowin_test.go new file mode 100644 index 0000000..fdedf71 --- /dev/null +++ b/msg_nowin_test.go @@ -0,0 +1,29 @@ +//go:build !windows + +package mail + +import "testing" + +// TestMsg_WriteToSendmailWithCommand tests the WriteToSendmailWithCommand() method of the Msg +func TestMsg_WriteToSendmailWithCommand(t *testing.T) { + tests := []struct { + name string + sp string + sf bool + }{ + {"Sendmail path: /dev/null", "/dev/null", true}, + {"Sendmail path: /bin/cat", "/bin/cat", true}, + {"Sendmail path: /is/invalid", "/is/invalid", true}, + {"Sendmail path: /bin/echo", "/bin/echo", false}, + } + m := NewMsg() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m.SetBodyString(TypeTextPlain, "Plain") + if err := m.WriteToSendmailWithCommand(tt.sp); err != nil && !tt.sf { + t.Errorf("WriteToSendmailWithCommand() failed: %s", err) + } + m.Reset() + }) + } +} diff --git a/msg_test.go b/msg_test.go index 5005f45..240e31c 100644 --- a/msg_test.go +++ b/msg_test.go @@ -1138,27 +1138,3 @@ func TestMsg_Write(t *testing.T) { fmt.Printf("%s", wbuf.String()) } } - -// TestMsg_WriteToSendmailWithCommand tests the WriteToSendmailWithCommand() method of the Msg -func TestMsg_WriteToSendmailWithCommand(t *testing.T) { - tests := []struct { - name string - sp string - sf bool - }{ - {"Sendmail path: /dev/null", "/dev/null", true}, - {"Sendmail path: /bin/cat", "/bin/cat", true}, - {"Sendmail path: /is/invalid", "/is/invalid", true}, - {"Sendmail path: /bin/echo", "/bin/echo", false}, - } - m := NewMsg() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - m.SetBodyString(TypeTextPlain, "Plain") - if err := m.WriteToSendmailWithCommand(tt.sp); err != nil && !tt.sf { - t.Errorf("WriteToSendmailWithCommand() failed: %s", err) - } - m.Reset() - }) - } -}