forked from davrux/go-smtptester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
64 lines (49 loc) · 1.1 KB
/
server_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
package smtptester
import (
"log"
"os"
"testing"
"time"
s "net/smtp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var (
srv = Standard()
)
func TestMain(m *testing.M) {
go func() {
if err := srv.ListenAndServe(); err != nil {
log.Printf("smtp server response %s", err)
}
}()
// Wait sec to let server come up.
time.Sleep(time.Second)
exitVal := m.Run()
srv.Close()
os.Exit(exitVal)
}
func TestBackend_AddLoad(t *testing.T) {
b := Backend{}
m := &Mail{
From: "[email protected]",
Recipients: []string{"[email protected]"},
Data: []byte("test"),
}
b.Add(m)
m1, found := b.Load(m.From, m.Recipients)
assert.True(t, found)
assert.Equal(t, m, m1)
}
func TestSendMail(t *testing.T) {
from := "[email protected]"
recipients := []string{"[email protected]"}
data := []byte("Test mail\r\n")
// Send without TLS.
require.Nil(t, s.SendMail(srv.Addr, nil, from, recipients, data))
m, found := GetBackend(srv).Load(from, recipients)
assert.True(t, found)
assert.Equal(t, from, m.From)
assert.Equal(t, recipients, m.Recipients)
assert.Equal(t, data, m.Data)
}