FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gin/lib/proxy_test.go at master · 95Key/gin · GitHub
95Key
gin
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gin
/
lib
/
proxy_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
114 lines (94 loc) · 2.62 KB
Breadcrumbs
gin
/
lib
/
proxy_test.go
Copy path
File metadata and controls
114 lines (94 loc) · 2.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package
gin_test
import
(
"fmt"
"github.com/codegangsta/gin/lib"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func
Test_NewProxy
(
t
*
testing.
T
) {
builder
:=
NewMockBuilder
()
runner
:=
NewMockRunner
()
proxy
:=
gin
.
NewProxy
(
builder
,
runner
)
expect
(
t
,
proxy
!=
nil
,
true
)
}
func
Test_Proxy_Run
(
t
*
testing.
T
) {
builder
:=
NewMockBuilder
()
runner
:=
NewMockRunner
()
proxy
:=
gin
.
NewProxy
(
builder
,
runner
)
config
:=
&
gin.
Config
{}
proxy
.
Run
(
config
)
defer
proxy
.
Close
()
}
func
Test_Proxying
(
t
*
testing.
T
) {
builder
:=
NewMockBuilder
()
runner
:=
NewMockRunner
()
proxy
:=
gin
.
NewProxy
(
builder
,
runner
)
// create a test server and see if we can proxy a request
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http.
ResponseWriter
,
r
*
http.
Request
) {
fmt
.
Fprintln
(
w
,
"Hello world"
)
}))
defer
ts
.
Close
()
config
:=
&
gin.
Config
{
Port
:
5678
,
ProxyTo
:
ts
.
URL
,
}
err
:=
proxy
.
Run
(
config
)
defer
proxy
.
Close
()
expect
(
t
,
err
,
nil
)
res
,
err
:=
http
.
Get
(
"http://localhost:5678"
)
expect
(
t
,
err
,
nil
)
expect
(
t
,
res
==
nil
,
false
)
greeting
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
expect
(
t
,
fmt
.
Sprintf
(
"%s"
,
greeting
),
"Hello world
\n
"
)
expect
(
t
,
runner
.
DidRun
,
true
)
}
func
Test_Proxying_Websocket
(
t
*
testing.
T
) {
builder
:=
NewMockBuilder
()
runner
:=
NewMockRunner
()
proxy
:=
gin
.
NewProxy
(
builder
,
runner
)
// create a test server and see if we can proxy a websocket request
ts
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http.
ResponseWriter
,
r
*
http.
Request
) {
fmt
.
Fprintln
(
w
,
"Hello world"
)
}))
defer
ts
.
Close
()
config
:=
&
gin.
Config
{
Port
:
5678
,
ProxyTo
:
ts
.
URL
,
}
err
:=
proxy
.
Run
(
config
)
defer
proxy
.
Close
()
expect
(
t
,
err
,
nil
)
client
:=
&
http.
Client
{}
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"http://localhost:5678"
,
nil
)
req
.
Header
.
Set
(
"Connection"
,
"Upgrade"
)
req
.
Header
.
Set
(
"Upgrade"
,
"Websocket"
)
res
,
_
:=
client
.
Do
(
req
)
expect
(
t
,
err
,
nil
)
expect
(
t
,
res
==
nil
,
false
)
greeting
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
expect
(
t
,
fmt
.
Sprintf
(
"%s"
,
greeting
),
"Hello world
\n
"
)
expect
(
t
,
runner
.
DidRun
,
true
)
}
func
Test_Proxying_Build_Errors
(
t
*
testing.
T
) {
builder
:=
NewMockBuilder
()
builder
.
MockErrors
=
"Foo bar here are some errors"
runner
:=
NewMockRunner
()
proxy
:=
gin
.
NewProxy
(
builder
,
runner
)
config
:=
&
gin.
Config
{
Port
:
5679
,
ProxyTo
:
"http://localhost:3000"
,
}
err
:=
proxy
.
Run
(
config
)
defer
proxy
.
Close
()
expect
(
t
,
err
,
nil
)
res
,
err
:=
http
.
Get
(
"http://localhost:5679"
)
expect
(
t
,
err
,
nil
)
expect
(
t
,
res
==
nil
,
false
)
errors
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
expect
(
t
,
fmt
.
Sprintf
(
"%s"
,
errors
),
"Foo bar here are some errors"
)
}
Back
|
FazBrowse Home
|
New Git URL