MCPcopy Index your code
hub / github.com/codegangsta/gin / Test_Proxying_Websocket

Function Test_Proxying_Websocket

lib/proxy_test.go:60–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func Test_Proxying_Websocket(t *testing.T) {
61 builder := NewMockBuilder()
62 runner := NewMockRunner()
63 proxy := gin.NewProxy(builder, runner)
64
65 // create a test server and see if we can proxy a websocket request
66 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
67 fmt.Fprintln(w, "Hello world")
68 }))
69 defer ts.Close()
70
71 config := &gin.Config{
72 Port: 5678,
73 ProxyTo: ts.URL,
74 }
75
76 err := proxy.Run(config)
77 defer proxy.Close()
78 expect(t, err, nil)
79
80 client := &http.Client{}
81 req, _ := http.NewRequest("GET", "http://localhost:5678", nil)
82 req.Header.Set("Connection", "Upgrade")
83 req.Header.Set("Upgrade", "Websocket")
84 res, _ := client.Do(req)
85 expect(t, err, nil)
86 expect(t, res == nil, false)
87 greeting, err := ioutil.ReadAll(res.Body)
88 res.Body.Close()
89 expect(t, fmt.Sprintf("%s", greeting), "Hello world\n")
90 expect(t, runner.DidRun, true)
91}
92
93func Test_Proxying_Build_Errors(t *testing.T) {
94 builder := NewMockBuilder()

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
RunMethod · 0.95
NewMockBuilderFunction · 0.85
NewMockRunnerFunction · 0.85
expectFunction · 0.85

Tested by

no test coverage detected