forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
accepter_test.go
56 lines (45 loc) · 1.27 KB
/
accepter_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
package quickfix
import (
"net"
"testing"
"github.com/armon/go-proxyproto"
"github.com/stretchr/testify/assert"
)
func TestAcceptor_Start(t *testing.T) {
settingsWithTCPProxy := NewSettings()
settingsWithTCPProxy.GlobalSettings().Set("UseTCPProxy", "Y")
settingsWithNoTCPProxy := NewSettings()
settingsWithNoTCPProxy.GlobalSettings().Set("UseTCPProxy", "N")
genericSettings := NewSettings()
const (
GenericListener = iota
ProxyListener
)
acceptorStartTests := []struct {
name string
settings *Settings
listenerType int
}{
{"with TCP proxy set", settingsWithTCPProxy, ProxyListener},
{"with no TCP proxy set", settingsWithNoTCPProxy, GenericListener},
{"no TCP proxy configuration set", genericSettings, GenericListener},
}
for _, tt := range acceptorStartTests {
t.Run(tt.name, func(t *testing.T) {
tt.settings.GlobalSettings().Set("SocketAcceptPort", "5001")
acceptor := &Acceptor{settings: tt.settings}
if err := acceptor.Start(); err != nil {
assert.NotNil(t, err)
}
if tt.listenerType == ProxyListener {
_, ok := acceptor.listener.(*proxyproto.Listener)
assert.True(t, ok)
}
if tt.listenerType == GenericListener {
_, ok := acceptor.listener.(*net.TCPListener)
assert.True(t, ok)
}
acceptor.Stop()
})
}
}