forked from smarty/cproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_protocol_initializer_test.go
56 lines (44 loc) · 1.6 KB
/
proxy_protocol_initializer_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 cproxy
import (
"testing"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func TestProxyProtocolInitializerFixture(t *testing.T) {
gunit.Run(new(ProxyProtocolInitializerFixture), t)
}
type ProxyProtocolInitializerFixture struct {
*gunit.Fixture
client *TestSocket
server *TestSocket
initializer *proxyProtocolInitializer
}
func (this *ProxyProtocolInitializerFixture) Setup() {
this.client = NewTestSocket()
this.server = NewTestSocket()
this.initializer = newProxyProtocolInitializer()
}
func (this *ProxyProtocolInitializerFixture) TestIPv4ProtocolV1() {
this.client.address = "1.1.1.1"
this.client.port = 1234
this.server.address = "2.2.2.2"
this.server.port = 5678
result := this.initializer.Initialize(this.client, this.server)
this.So(result, should.BeTrue)
this.So(this.server.writeBuffer.String(), should.Equal, "PROXY TCP4 1.1.1.1 2.2.2.2 1234 5678\r\n")
this.So(this.client.writeBuffer.String(), should.BeEmpty)
this.So(this.server.close, should.Equal, 0)
this.So(this.client.close, should.Equal, 0)
}
func (this *ProxyProtocolInitializerFixture) TestIPv6ProtocolV1() {
this.client.address = "2001:db8::68"
this.client.port = 1234
this.server.address = "2.2.2.2"
this.server.port = 5678
result := this.initializer.Initialize(this.client, this.server)
this.So(result, should.BeTrue)
this.So(this.server.writeBuffer.String(), should.Equal, "PROXY TCP6 2001:db8::68 2.2.2.2 1234 5678\r\n")
this.So(this.client.writeBuffer.String(), should.BeEmpty)
this.So(this.server.close, should.Equal, 0)
this.So(this.client.close, should.Equal, 0)
}