(t *testing.T)
| 58 | } |
| 59 | |
| 60 | func 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 | |
| 93 | func Test_Proxying_Build_Errors(t *testing.T) { |
| 94 | builder := NewMockBuilder() |
nothing calls this directly
no test coverage detected