@@ -189,30 +189,44 @@ func TestServeHTTP_GraphQLIntrospectionPassthrough(t *testing.T) {
189189}
190190
191191func TestServeHTTP_GraphQLPreservesQueryString (t * testing.T ) {
192- var receivedURL string
193- upstream := httptest . NewServer ( http . HandlerFunc ( func ( w http. ResponseWriter , r * http. Request ) {
194- receivedURL = r . URL . RequestURI ()
195- w . Header (). Set ( "Content-Type" , "application/json" )
196- w . WriteHeader ( http . StatusOK )
197- _ , err := w . Write ([] byte ( `{"data":{"repository":{"issues":{"nodes":[]}}}}` ))
198- require . NoError ( t , err )
199- }))
200- defer upstream . Close ()
192+ tests := [] struct {
193+ name string
194+ path string
195+ wantPath string
196+ }{
197+ { name : "graphql path" , path : "/graphql?foo=bar" , wantPath : "/graphql?foo=bar" },
198+ { name : "ghes api graphql path" , path : "/api/graphql?foo=bar" , wantPath : "/api/graphql?foo=bar" },
199+ { name : "gh host prefixed graphql path" , path : "/api/v3/graphql?foo=bar" , wantPath : "/graphql?foo=bar" },
200+ }
201201
202- s := newTestServer (t , upstream .URL )
203- h := & proxyHandler {server : s }
202+ for _ , tt := range tests {
203+ t .Run (tt .name , func (t * testing.T ) {
204+ var receivedURL string
205+ upstream := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
206+ receivedURL = r .URL .RequestURI ()
207+ w .Header ().Set ("Content-Type" , "application/json" )
208+ w .WriteHeader (http .StatusOK )
209+ _ , err := w .Write ([]byte (`{"data":{"repository":{"issues":{"nodes":[]}}}}` ))
210+ require .NoError (t , err )
211+ }))
212+ defer upstream .Close ()
204213
205- gqlBody , err := json .Marshal (map [string ]interface {}{
206- "query" : `{ repository(owner:"org", name:"repo") { issues(first: 10) { nodes { id } } } }` ,
207- })
208- require .NoError (t , err )
209- req := httptest .NewRequest (http .MethodPost , "/graphql?foo=bar" , bytes .NewReader (gqlBody ))
210- req .Header .Set ("Content-Type" , "application/json" )
211- w := httptest .NewRecorder ()
212- h .ServeHTTP (w , req )
214+ s := newTestServer (t , upstream .URL )
215+ h := & proxyHandler {server : s }
213216
214- assert .Equal (t , http .StatusOK , w .Code )
215- assert .Equal (t , "/graphql?foo=bar" , receivedURL )
217+ gqlBody , err := json .Marshal (map [string ]interface {}{
218+ "query" : `{ repository(owner:"org", name:"repo") { issues(first: 10) { nodes { id } } } }` ,
219+ })
220+ require .NoError (t , err )
221+ req := httptest .NewRequest (http .MethodPost , tt .path , bytes .NewReader (gqlBody ))
222+ req .Header .Set ("Content-Type" , "application/json" )
223+ w := httptest .NewRecorder ()
224+ h .ServeHTTP (w , req )
225+
226+ assert .Equal (t , http .StatusOK , w .Code )
227+ assert .Equal (t , tt .wantPath , receivedURL )
228+ })
229+ }
216230}
217231
218232// ─── ServeHTTP: query string is forwarded on REST GET ────────────────────────
0 commit comments