-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathintegration_test.go
More file actions
82 lines (70 loc) · 1.67 KB
/
integration_test.go
File metadata and controls
82 lines (70 loc) · 1.67 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package warp
import (
"bytes"
"fmt"
"log"
"strings"
"testing"
"time"
)
func TestIntegration(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ip := "127.0.0.1"
warpPort := 10025
smtpPort := 11025
hostname := "example.local"
var (
warpLog bytes.Buffer
smtpLog bytes.Buffer
)
messages := make(chan ReceivedMessage, 1)
go func() {
specifiedDstIP = ip
specifiedDstPort = smtpPort
w := &Server{
Addr: ip,
Port: warpPort,
Verbose: true,
log: log.New(&warpLog, "", log.Ldate|log.Ltime|log.Lmicroseconds),
}
if err := w.Start(); err != nil {
t.Errorf("warp raised error: %s", err)
}
}()
go func() {
s := &SMTPServer{
IP: ip,
Port: smtpPort,
Hostname: hostname,
log: log.New(&smtpLog, "", log.Ldate|log.Ltime|log.Lmicroseconds),
OnMessage: func(msg ReceivedMessage) {
messages <- msg
},
}
if err := s.Serve(); err != nil {
t.Errorf("smtp server raised error: %s", err)
}
}()
WaitForServerListen(ip, warpPort)
WaitForServerListen(ip, smtpPort)
c := &SMTPClient{IP: ip, Port: warpPort}
err := c.SendEmail()
fmt.Printf("\nWarp Server:\n%s", &warpLog)
fmt.Printf("\nSMTP Server:\n%s\n", &smtpLog)
if err != nil {
t.Fatalf("smtp client raised error: %s", err)
}
select {
case msg := <-messages:
if msg.MailFrom != "alice@example.test" {
t.Errorf("MailFrom = %q, want %q", msg.MailFrom, "alice@example.test")
}
if !strings.Contains(string(msg.Data), "Subject: Test") {
t.Errorf("Data does not contain 'Subject: Test': %s", string(msg.Data[:min(len(msg.Data), 200)]))
}
case <-time.After(5 * time.Second):
t.Fatal("timed out waiting for message from SMTP server")
}
}