-
Notifications
You must be signed in to change notification settings - Fork 34
/
config_test.go
49 lines (39 loc) · 1.25 KB
/
config_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
package cproxy
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestConfigFixture(t *testing.T) {
gunit.Run(new(ConfigFixture), t)
}
type ConfigFixture struct {
*gunit.Fixture
clientSocket *TestSocket
serverSocket *TestSocket
clientConnector *TestClientConnector
dialer *TestDialer
handler http.Handler
}
func (this *ConfigFixture) Setup() {
this.clientSocket = NewTestSocket()
this.serverSocket = NewTestSocket()
this.clientConnector = NewTestClientConnector(this.clientSocket)
this.dialer = NewTestDialer(this.serverSocket)
this.handler = New(
Options.ClientConnector(this.clientConnector),
Options.Dialer(this.dialer),
)
}
func (this *ConfigFixture) TestEndToEnd() {
request := httptest.NewRequest("CONNECT", "host", nil)
response := httptest.NewRecorder()
this.clientSocket.readBuffer.WriteString("from client")
this.serverSocket.readBuffer.WriteString("from server")
this.handler.ServeHTTP(response, request)
this.So(this.dialer.address, should.Equal, "host")
this.So(this.clientSocket.writeBuffer.String(), should.Equal, "HTTP/1.1 200 OK\r\n\r\nfrom server")
this.So(this.serverSocket.writeBuffer.String(), should.Equal, "from client")
}