@@ -247,6 +247,155 @@ func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) {
247247 }
248248}
249249
250+ func TestRepositoriesService_DownloadContentsWithMeta_Success (t * testing.T ) {
251+ client , mux , serverURL , teardown := setup ()
252+ defer teardown ()
253+ mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
254+ testMethod (t , r , "GET" )
255+ fmt .Fprint (w , `[{
256+ "type": "file",
257+ "name": "f",
258+ "download_url": "` + serverURL + baseURLPath + `/download/f"
259+ }]` )
260+ })
261+ mux .HandleFunc ("/download/f" , func (w http.ResponseWriter , r * http.Request ) {
262+ testMethod (t , r , "GET" )
263+ fmt .Fprint (w , "foo" )
264+ })
265+
266+ ctx := context .Background ()
267+ r , c , resp , err := client .Repositories .DownloadContentsWithMeta (ctx , "o" , "r" , "d/f" , nil )
268+ if err != nil {
269+ t .Errorf ("Repositories.DownloadContentsWithMeta returned error: %v" , err )
270+ }
271+
272+ if got , want := resp .Response .StatusCode , http .StatusOK ; got != want {
273+ t .Errorf ("Repositories.DownloadContentsWithMeta returned status code %v, want %v" , got , want )
274+ }
275+
276+ bytes , err := ioutil .ReadAll (r )
277+ if err != nil {
278+ t .Errorf ("Error reading response body: %v" , err )
279+ }
280+ r .Close ()
281+
282+ if got , want := string (bytes ), "foo" ; got != want {
283+ t .Errorf ("Repositories.DownloadContentsWithMeta returned %v, want %v" , got , want )
284+ }
285+
286+ if c != nil && c .Name != nil {
287+ if got , want := * c .Name , "f" ; got != want {
288+ t .Errorf ("Repositories.DownloadContentsWithMeta returned content name %v, want %v" , got , want )
289+ }
290+ } else {
291+ t .Errorf ("Returned RepositoryContent is null" )
292+ }
293+
294+ const methodName = "DownloadContentsWithMeta"
295+ testBadOptions (t , methodName , func () (err error ) {
296+ _ , _ , _ , err = client .Repositories .DownloadContentsWithMeta (ctx , "\n " , "\n " , "\n " , nil )
297+ return err
298+ })
299+
300+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
301+ got , cot , resp , err := client .Repositories .DownloadContentsWithMeta (ctx , "o" , "r" , "d/f" , nil )
302+ if got != nil {
303+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
304+ }
305+ if cot != nil {
306+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , cot )
307+ }
308+ return resp , err
309+ })
310+ }
311+
312+ func TestRepositoriesService_DownloadContentsWithMeta_FailedResponse (t * testing.T ) {
313+ client , mux , serverURL , teardown := setup ()
314+ defer teardown ()
315+ mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
316+ testMethod (t , r , "GET" )
317+ fmt .Fprint (w , `[{
318+ "type": "file",
319+ "name": "f",
320+ "download_url": "` + serverURL + baseURLPath + `/download/f"
321+ }]` )
322+ })
323+ mux .HandleFunc ("/download/f" , func (w http.ResponseWriter , r * http.Request ) {
324+ testMethod (t , r , "GET" )
325+ w .WriteHeader (http .StatusInternalServerError )
326+ fmt .Fprint (w , "foo error" )
327+ })
328+
329+ ctx := context .Background ()
330+ r , c , resp , err := client .Repositories .DownloadContentsWithMeta (ctx , "o" , "r" , "d/f" , nil )
331+ if err != nil {
332+ t .Errorf ("Repositories.DownloadContentsWithMeta returned error: %v" , err )
333+ }
334+
335+ if got , want := resp .Response .StatusCode , http .StatusInternalServerError ; got != want {
336+ t .Errorf ("Repositories.DownloadContentsWithMeta returned status code %v, want %v" , got , want )
337+ }
338+
339+ bytes , err := ioutil .ReadAll (r )
340+ if err != nil {
341+ t .Errorf ("Error reading response body: %v" , err )
342+ }
343+ r .Close ()
344+
345+ if got , want := string (bytes ), "foo error" ; got != want {
346+ t .Errorf ("Repositories.DownloadContentsWithMeta returned %v, want %v" , got , want )
347+ }
348+
349+ if c != nil && c .Name != nil {
350+ if got , want := * c .Name , "f" ; got != want {
351+ t .Errorf ("Repositories.DownloadContentsWithMeta returned content name %v, want %v" , got , want )
352+ }
353+ } else {
354+ t .Errorf ("Returned RepositoryContent is null" )
355+ }
356+ }
357+
358+ func TestRepositoriesService_DownloadContentsWithMeta_NoDownloadURL (t * testing.T ) {
359+ client , mux , _ , teardown := setup ()
360+ defer teardown ()
361+ mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
362+ testMethod (t , r , "GET" )
363+ fmt .Fprint (w , `[{
364+ "type": "file",
365+ "name": "f",
366+ }]` )
367+ })
368+
369+ ctx := context .Background ()
370+ _ , _ , resp , err := client .Repositories .DownloadContentsWithMeta (ctx , "o" , "r" , "d/f" , nil )
371+ if err == nil {
372+ t .Errorf ("Repositories.DownloadContentsWithMeta did not return expected error" )
373+ }
374+
375+ if resp == nil {
376+ t .Errorf ("Repositories.DownloadContentsWithMeta did not return expected response" )
377+ }
378+ }
379+
380+ func TestRepositoriesService_DownloadContentsWithMeta_NoFile (t * testing.T ) {
381+ client , mux , _ , teardown := setup ()
382+ defer teardown ()
383+ mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
384+ testMethod (t , r , "GET" )
385+ fmt .Fprint (w , `[]` )
386+ })
387+
388+ ctx := context .Background ()
389+ _ , _ , resp , err := client .Repositories .DownloadContentsWithMeta (ctx , "o" , "r" , "d/f" , nil )
390+ if err == nil {
391+ t .Errorf ("Repositories.DownloadContentsWithMeta did not return expected error" )
392+ }
393+
394+ if resp == nil {
395+ t .Errorf ("Repositories.DownloadContentsWithMeta did not return expected response" )
396+ }
397+ }
398+
250399func TestRepositoriesService_GetContents_File (t * testing.T ) {
251400 client , mux , _ , teardown := setup ()
252401 defer teardown ()
0 commit comments