Skip to content

Commit c389c72

Browse files
authored
Improve gists.go coverage (#1739)
1 parent 6e32c1e commit c389c72

File tree

1 file changed

+224
-0
lines changed

1 file changed

+224
-0
lines changed

github/gists_test.go

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ func TestGistsService_List_specifiedUser(t *testing.T) {
249249
if !reflect.DeepEqual(gists, want) {
250250
t.Errorf("Gists.List returned %+v, want %+v", gists, want)
251251
}
252+
253+
const methodName = "List"
254+
testBadOptions(t, methodName, func() (err error) {
255+
_, _, err = client.Gists.List(ctx, "\n", opt)
256+
return err
257+
})
258+
259+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
260+
got, resp, err := client.Gists.List(ctx, "u", opt)
261+
if got != nil {
262+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
263+
}
264+
return resp, err
265+
})
252266
}
253267

254268
func TestGistsService_List_authenticatedUser(t *testing.T) {
@@ -270,6 +284,20 @@ func TestGistsService_List_authenticatedUser(t *testing.T) {
270284
if !reflect.DeepEqual(gists, want) {
271285
t.Errorf("Gists.List returned %+v, want %+v", gists, want)
272286
}
287+
288+
const methodName = "List"
289+
testBadOptions(t, methodName, func() (err error) {
290+
_, _, err = client.Gists.List(ctx, "\n", nil)
291+
return err
292+
})
293+
294+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
295+
got, resp, err := client.Gists.List(ctx, "", nil)
296+
if got != nil {
297+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
298+
}
299+
return resp, err
300+
})
273301
}
274302

275303
func TestGistsService_List_invalidUser(t *testing.T) {
@@ -306,6 +334,15 @@ func TestGistsService_ListAll(t *testing.T) {
306334
if !reflect.DeepEqual(gists, want) {
307335
t.Errorf("Gists.ListAll returned %+v, want %+v", gists, want)
308336
}
337+
338+
const methodName = "ListAll"
339+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
340+
got, resp, err := client.Gists.ListAll(ctx, opt)
341+
if got != nil {
342+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
343+
}
344+
return resp, err
345+
})
309346
}
310347

311348
func TestGistsService_ListStarred(t *testing.T) {
@@ -333,6 +370,15 @@ func TestGistsService_ListStarred(t *testing.T) {
333370
if !reflect.DeepEqual(gists, want) {
334371
t.Errorf("Gists.ListStarred returned %+v, want %+v", gists, want)
335372
}
373+
374+
const methodName = "ListStarred"
375+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
376+
got, resp, err := client.Gists.ListStarred(ctx, opt)
377+
if got != nil {
378+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
379+
}
380+
return resp, err
381+
})
336382
}
337383

338384
func TestGistsService_Get(t *testing.T) {
@@ -354,6 +400,20 @@ func TestGistsService_Get(t *testing.T) {
354400
if !reflect.DeepEqual(gist, want) {
355401
t.Errorf("Gists.Get returned %+v, want %+v", gist, want)
356402
}
403+
404+
const methodName = "Get"
405+
testBadOptions(t, methodName, func() (err error) {
406+
_, _, err = client.Gists.Get(ctx, "\n")
407+
return err
408+
})
409+
410+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
411+
got, resp, err := client.Gists.Get(ctx, "1")
412+
if got != nil {
413+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
414+
}
415+
return resp, err
416+
})
357417
}
358418

359419
func TestGistsService_Get_invalidID(t *testing.T) {
@@ -384,6 +444,20 @@ func TestGistsService_GetRevision(t *testing.T) {
384444
if !reflect.DeepEqual(gist, want) {
385445
t.Errorf("Gists.Get returned %+v, want %+v", gist, want)
386446
}
447+
448+
const methodName = "GetRevision"
449+
testBadOptions(t, methodName, func() (err error) {
450+
_, _, err = client.Gists.GetRevision(ctx, "\n", "\n")
451+
return err
452+
})
453+
454+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
455+
got, resp, err := client.Gists.GetRevision(ctx, "1", "s")
456+
if got != nil {
457+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
458+
}
459+
return resp, err
460+
})
387461
}
388462

389463
func TestGistsService_GetRevision_invalidID(t *testing.T) {
@@ -447,6 +521,15 @@ func TestGistsService_Create(t *testing.T) {
447521
if !reflect.DeepEqual(gist, want) {
448522
t.Errorf("Gists.Create returned %+v, want %+v", gist, want)
449523
}
524+
525+
const methodName = "Create"
526+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
527+
got, resp, err := client.Gists.Create(ctx, input)
528+
if got != nil {
529+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
530+
}
531+
return resp, err
532+
})
450533
}
451534

452535
func TestGistsService_Edit(t *testing.T) {
@@ -504,6 +587,20 @@ func TestGistsService_Edit(t *testing.T) {
504587
if !reflect.DeepEqual(gist, want) {
505588
t.Errorf("Gists.Edit returned %+v, want %+v", gist, want)
506589
}
590+
591+
const methodName = "Edit"
592+
testBadOptions(t, methodName, func() (err error) {
593+
_, _, err = client.Gists.Edit(ctx, "\n", input)
594+
return err
595+
})
596+
597+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
598+
got, resp, err := client.Gists.Edit(ctx, "1", input)
599+
if got != nil {
600+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
601+
}
602+
return resp, err
603+
})
507604
}
508605

509606
func TestGistsService_Edit_invalidID(t *testing.T) {
@@ -561,6 +658,20 @@ func TestGistsService_ListCommits(t *testing.T) {
561658
if !reflect.DeepEqual(gistCommits, want) {
562659
t.Errorf("Gists.ListCommits returned %+v, want %+v", gistCommits, want)
563660
}
661+
662+
const methodName = "ListCommits"
663+
testBadOptions(t, methodName, func() (err error) {
664+
_, _, err = client.Gists.ListCommits(ctx, "\n", nil)
665+
return err
666+
})
667+
668+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
669+
got, resp, err := client.Gists.ListCommits(ctx, "1", nil)
670+
if got != nil {
671+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
672+
}
673+
return resp, err
674+
})
564675
}
565676

566677
func TestGistsService_ListCommits_withOptions(t *testing.T) {
@@ -580,6 +691,20 @@ func TestGistsService_ListCommits_withOptions(t *testing.T) {
580691
if err != nil {
581692
t.Errorf("Gists.ListCommits returned error: %v", err)
582693
}
694+
695+
const methodName = "ListCommits"
696+
testBadOptions(t, methodName, func() (err error) {
697+
_, _, err = client.Gists.ListCommits(ctx, "\n", &ListOptions{Page: 2})
698+
return err
699+
})
700+
701+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
702+
got, resp, err := client.Gists.ListCommits(ctx, "1", &ListOptions{Page: 2})
703+
if got != nil {
704+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
705+
}
706+
return resp, err
707+
})
583708
}
584709

585710
func TestGistsService_ListCommits_invalidID(t *testing.T) {
@@ -604,6 +729,16 @@ func TestGistsService_Delete(t *testing.T) {
604729
if err != nil {
605730
t.Errorf("Gists.Delete returned error: %v", err)
606731
}
732+
733+
const methodName = "Delete"
734+
testBadOptions(t, methodName, func() (err error) {
735+
_, err = client.Gists.Delete(ctx, "\n")
736+
return err
737+
})
738+
739+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
740+
return client.Gists.Delete(ctx, "1")
741+
})
607742
}
608743

609744
func TestGistsService_Delete_invalidID(t *testing.T) {
@@ -628,6 +763,16 @@ func TestGistsService_Star(t *testing.T) {
628763
if err != nil {
629764
t.Errorf("Gists.Star returned error: %v", err)
630765
}
766+
767+
const methodName = "Star"
768+
testBadOptions(t, methodName, func() (err error) {
769+
_, err = client.Gists.Star(ctx, "\n")
770+
return err
771+
})
772+
773+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
774+
return client.Gists.Star(ctx, "1")
775+
})
631776
}
632777

633778
func TestGistsService_Star_invalidID(t *testing.T) {
@@ -652,6 +797,16 @@ func TestGistsService_Unstar(t *testing.T) {
652797
if err != nil {
653798
t.Errorf("Gists.Unstar returned error: %v", err)
654799
}
800+
801+
const methodName = "Unstar"
802+
testBadOptions(t, methodName, func() (err error) {
803+
_, err = client.Gists.Unstar(ctx, "\n")
804+
return err
805+
})
806+
807+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
808+
return client.Gists.Unstar(ctx, "1")
809+
})
655810
}
656811

657812
func TestGistsService_Unstar_invalidID(t *testing.T) {
@@ -680,6 +835,20 @@ func TestGistsService_IsStarred_hasStar(t *testing.T) {
680835
if want := true; star != want {
681836
t.Errorf("Gists.Starred returned %+v, want %+v", star, want)
682837
}
838+
839+
const methodName = "IsStarred"
840+
testBadOptions(t, methodName, func() (err error) {
841+
_, _, err = client.Gists.IsStarred(ctx, "\n")
842+
return err
843+
})
844+
845+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
846+
got, resp, err := client.Gists.IsStarred(ctx, "1")
847+
if got {
848+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want false", methodName, got)
849+
}
850+
return resp, err
851+
})
683852
}
684853

685854
func TestGistsService_IsStarred_noStar(t *testing.T) {
@@ -699,6 +868,20 @@ func TestGistsService_IsStarred_noStar(t *testing.T) {
699868
if want := false; star != want {
700869
t.Errorf("Gists.Starred returned %+v, want %+v", star, want)
701870
}
871+
872+
const methodName = "IsStarred"
873+
testBadOptions(t, methodName, func() (err error) {
874+
_, _, err = client.Gists.IsStarred(ctx, "\n")
875+
return err
876+
})
877+
878+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
879+
got, resp, err := client.Gists.IsStarred(ctx, "1")
880+
if got {
881+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want false", methodName, got)
882+
}
883+
return resp, err
884+
})
702885
}
703886

704887
func TestGistsService_IsStarred_invalidID(t *testing.T) {
@@ -729,6 +912,20 @@ func TestGistsService_Fork(t *testing.T) {
729912
if !reflect.DeepEqual(gist, want) {
730913
t.Errorf("Gists.Fork returned %+v, want %+v", gist, want)
731914
}
915+
916+
const methodName = "Fork"
917+
testBadOptions(t, methodName, func() (err error) {
918+
_, _, err = client.Gists.Fork(ctx, "\n")
919+
return err
920+
})
921+
922+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
923+
got, resp, err := client.Gists.Fork(ctx, "1")
924+
if got != nil {
925+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
926+
}
927+
return resp, err
928+
})
732929
}
733930

734931
func TestGistsService_ListForks(t *testing.T) {
@@ -767,6 +964,19 @@ func TestGistsService_ListForks(t *testing.T) {
767964
t.Errorf("Gists.ListForks returned %+v, want %+v", gistForks, want)
768965
}
769966

967+
const methodName = "ListForks"
968+
testBadOptions(t, methodName, func() (err error) {
969+
_, _, err = client.Gists.ListForks(ctx, "\n", nil)
970+
return err
971+
})
972+
973+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
974+
got, resp, err := client.Gists.ListForks(ctx, "1", nil)
975+
if got != nil {
976+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
977+
}
978+
return resp, err
979+
})
770980
}
771981

772982
func TestGistsService_ListForks_withOptions(t *testing.T) {
@@ -822,4 +1032,18 @@ func TestGistsService_ListForks_withOptions(t *testing.T) {
8221032
if err == nil {
8231033
t.Error("rGists.ListForks returned err = nil, want error")
8241034
}
1035+
1036+
const methodName = "ListForks"
1037+
testBadOptions(t, methodName, func() (err error) {
1038+
_, _, err = client.Gists.ListForks(ctx, "\n", &ListOptions{Page: 2})
1039+
return err
1040+
})
1041+
1042+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
1043+
got, resp, err := client.Gists.ListForks(ctx, "1", &ListOptions{Page: 2})
1044+
if got != nil {
1045+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
1046+
}
1047+
return resp, err
1048+
})
8251049
}

0 commit comments

Comments
 (0)