(t *testing.T)
| 29 | } |
| 30 | |
| 31 | func Test_Proxying(t *testing.T) { |
| 32 | builder := NewMockBuilder() |
| 33 | runner := NewMockRunner() |
| 34 | proxy := gin.NewProxy(builder, runner) |
| 35 | |
| 36 | // create a test server and see if we can proxy a request |
| 37 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 38 | fmt.Fprintln(w, "Hello world") |
| 39 | })) |
| 40 | defer ts.Close() |
| 41 | |
| 42 | config := &gin.Config{ |
| 43 | Port: 5678, |
| 44 | ProxyTo: ts.URL, |
| 45 | } |
| 46 | |
| 47 | err := proxy.Run(config) |
| 48 | defer proxy.Close() |
| 49 | expect(t, err, nil) |
| 50 | |
| 51 | res, err := http.Get("http://localhost:5678") |
| 52 | expect(t, err, nil) |
| 53 | expect(t, res == nil, false) |
| 54 | greeting, err := ioutil.ReadAll(res.Body) |
| 55 | res.Body.Close() |
| 56 | expect(t, fmt.Sprintf("%s", greeting), "Hello world\n") |
| 57 | expect(t, runner.DidRun, true) |
| 58 | } |
| 59 | |
| 60 | func Test_Proxying_Websocket(t *testing.T) { |
| 61 | builder := NewMockBuilder() |
nothing calls this directly
no test coverage detected