(t *testing.T)
| 28 | var testTracer = otel.Tracer("bridge_test") |
| 29 | |
| 30 | func TestPassthroughRoutes(t *testing.T) { |
| 31 | t.Parallel() |
| 32 | |
| 33 | upstreamRespBody := "upstream response" |
| 34 | tests := []struct { |
| 35 | name string |
| 36 | baseURLPath string |
| 37 | reqPath string |
| 38 | reqHost string |
| 39 | reqRemoteAddr string |
| 40 | reqHeaders http.Header |
| 41 | expectRequestPath string |
| 42 | expectQuery string |
| 43 | expectHeaders http.Header |
| 44 | expectRespStatus int |
| 45 | expectRespBody string |
| 46 | }{ |
| 47 | { |
| 48 | name: "passthrough_route_no_path", |
| 49 | reqPath: "/v1/conversations", |
| 50 | expectRequestPath: "/v1/conversations", |
| 51 | expectRespStatus: http.StatusOK, |
| 52 | expectRespBody: upstreamRespBody, |
| 53 | }, |
| 54 | { |
| 55 | name: "base_URL_path_is_preserved_in_passthrough_routes", |
| 56 | baseURLPath: "/api/v2", |
| 57 | reqPath: "/v1/models", |
| 58 | expectRequestPath: "/api/v2/v1/models", |
| 59 | expectRespStatus: http.StatusOK, |
| 60 | expectRespBody: upstreamRespBody, |
| 61 | }, |
| 62 | { |
| 63 | name: "passthrough_route_break_parse_base_url", |
| 64 | baseURLPath: "/%zz", |
| 65 | reqPath: "/v1/models/", |
| 66 | expectRespStatus: http.StatusBadGateway, |
| 67 | expectRespBody: "invalid provider base URL", |
| 68 | }, |
| 69 | { |
| 70 | name: "passthrough_route_rejects_invalid_base_url_path", |
| 71 | baseURLPath: "/%25", |
| 72 | reqPath: "/v1/models", |
| 73 | expectRespStatus: http.StatusBadGateway, |
| 74 | expectRespBody: "invalid provider base URL", |
| 75 | }, |
| 76 | { |
| 77 | name: "proxy_headers_are_set_and_forwarded_chain_is_appended", |
| 78 | reqPath: "/v1/models", |
| 79 | reqHost: "client.example.com", |
| 80 | reqRemoteAddr: "1.1.1.1:1111", |
| 81 | reqHeaders: http.Header{ |
| 82 | "X-Forwarded-For": {"2.2.2.2, 3.3.3.3"}, |
| 83 | }, |
| 84 | expectRequestPath: "/v1/models", |
| 85 | expectRespStatus: http.StatusOK, |
| 86 | expectRespBody: upstreamRespBody, |
| 87 | expectHeaders: http.Header{ |
nothing calls this directly
no test coverage detected