-
Notifications
You must be signed in to change notification settings - Fork 3
/
integration_test.go
65 lines (55 loc) · 1.16 KB
/
integration_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
65
package warp
import (
"bytes"
"fmt"
"log"
"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
)
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),
}
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()
time.Sleep(1 * time.Second)
fmt.Printf("\nWarp Server:\n%s", &warpLog)
fmt.Printf("\nSMTP Server:\n%s\n", &smtpLog)
if err != nil {
t.Errorf("smtp client raised error: %s", err)
}
}