From ca507d063dfa6f03f982154e284b2e5cf218710e Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 20 Jul 2019 00:32:19 +0200 Subject: [PATCH] Fix ineffectual assignments and error handling in tests - Ignore ineffectual assignments - Check for error when reading keyring --- github/activity_test.go | 4 ++-- github/git_commits_test.go | 3 +++ github/pulls_reviewers_test.go | 8 +++---- github/repos_test.go | 40 +++++++++++++++++----------------- github/repos_traffic_test.go | 20 ++++++++--------- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/github/activity_test.go b/github/activity_test.go index 9c4e566fb7d..b577118aad3 100644 --- a/github/activity_test.go +++ b/github/activity_test.go @@ -25,7 +25,7 @@ func TestActivityService_List(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Activity.ListFeeds(ctx) + got, _, err := client.Activity.ListFeeds(ctx) if err != nil { t.Errorf("Activity.ListFeeds returned error: %v", err) } @@ -35,7 +35,7 @@ func TestActivityService_List(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Activity.ListFeeds(ctx) + got, resp, err := client.Activity.ListFeeds(ctx) if got != nil { t.Errorf("client.BaseURL.Path='' ListFeeds = %#v, want nil", got) } diff --git a/github/git_commits_test.go b/github/git_commits_test.go index 580e6b05515..f316f01e0fd 100644 --- a/github/git_commits_test.go +++ b/github/git_commits_test.go @@ -146,6 +146,9 @@ func TestGitService_CreateSignedCommitWithKey(t *testing.T) { defer teardown() s := strings.NewReader(testGPGKey) keyring, err := openpgp.ReadArmoredKeyRing(s) + if err != nil { + t.Errorf("Error reading keyring: %+v", err) + } date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") author := CommitAuthor{ diff --git a/github/pulls_reviewers_test.go b/github/pulls_reviewers_test.go index 8599bd777e7..98d6e656f49 100644 --- a/github/pulls_reviewers_test.go +++ b/github/pulls_reviewers_test.go @@ -26,7 +26,7 @@ func TestRequestReviewers(t *testing.T) { // This returns a PR, unmarshalling of which is tested elsewhere ctx := context.Background() - got, resp, err := client.PullRequests.RequestReviewers(ctx, "o", "r", 1, ReviewersRequest{Reviewers: []string{"octocat", "googlebot"}, TeamReviewers: []string{"justice-league", "injustice-league"}}) + got, _, err := client.PullRequests.RequestReviewers(ctx, "o", "r", 1, ReviewersRequest{Reviewers: []string{"octocat", "googlebot"}, TeamReviewers: []string{"justice-league", "injustice-league"}}) if err != nil { t.Errorf("PullRequests.RequestReviewers returned error: %v", err) } @@ -37,7 +37,7 @@ func TestRequestReviewers(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.PullRequests.RequestReviewers(ctx, "o", "r", 1, ReviewersRequest{Reviewers: []string{"octocat", "googlebot"}, TeamReviewers: []string{"justice-league", "injustice-league"}}) + got, resp, err := client.PullRequests.RequestReviewers(ctx, "o", "r", 1, ReviewersRequest{Reviewers: []string{"octocat", "googlebot"}, TeamReviewers: []string{"justice-league", "injustice-league"}}) if got != nil { t.Errorf("client.BaseURL.Path='' RequestReviewers = %#v, want nil", got) } @@ -99,7 +99,7 @@ func TestListReviewers(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.PullRequests.ListReviewers(ctx, "o", "r", 1, nil) + got, _, err := client.PullRequests.ListReviewers(ctx, "o", "r", 1, nil) if err != nil { t.Errorf("PullRequests.ListReviewers returned error: %v", err) } @@ -124,7 +124,7 @@ func TestListReviewers(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.PullRequests.ListReviewers(ctx, "o", "r", 1, nil) + got, resp, err := client.PullRequests.ListReviewers(ctx, "o", "r", 1, nil) if got != nil { t.Errorf("client.BaseURL.Path='' ListReviewers = %#v, want nil", got) } diff --git a/github/repos_test.go b/github/repos_test.go index ebc1d8a782c..75e09a83e4b 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -28,7 +28,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.List(ctx, "", nil) + got, _, err := client.Repositories.List(ctx, "", nil) if err != nil { t.Errorf("Repositories.List returned error: %v", err) } @@ -39,7 +39,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) { } // Test addOptions failure - got, resp, err = client.Repositories.List(ctx, "\n", &RepositoryListOptions{}) + _, _, err = client.Repositories.List(ctx, "\n", &RepositoryListOptions{}) if err == nil { t.Error("bad options List err = nil, want error") } @@ -47,7 +47,7 @@ func TestRepositoriesService_List_authenticatedUser(t *testing.T) { // Test s.client.Do failure client.BaseURL.Path = "/api-v3/" client.rateLimits[0].Reset.Time = time.Now().Add(10 * time.Minute) - got, resp, err = client.Repositories.List(ctx, "", nil) + got, resp, err := client.Repositories.List(ctx, "", nil) if got != nil { t.Errorf("rate.Reset.Time > now List = %#v, want nil", got) } @@ -148,7 +148,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) { ctx := context.Background() opt := &RepositoryListByOrgOptions{"forks", ListOptions{Page: 2}} - got, resp, err := client.Repositories.ListByOrg(ctx, "o", opt) + got, _, err := client.Repositories.ListByOrg(ctx, "o", opt) if err != nil { t.Errorf("Repositories.ListByOrg returned error: %v", err) } @@ -159,7 +159,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) { } // Test addOptions failure - got, resp, err = client.Repositories.ListByOrg(ctx, "\n", opt) + _, _, err = client.Repositories.ListByOrg(ctx, "\n", opt) if err == nil { t.Error("bad options ListByOrg err = nil, want error") } @@ -167,7 +167,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) { // Test s.client.Do failure client.BaseURL.Path = "/api-v3/" client.rateLimits[0].Reset.Time = time.Now().Add(10 * time.Minute) - got, resp, err = client.Repositories.ListByOrg(ctx, "o", opt) + got, resp, err := client.Repositories.ListByOrg(ctx, "o", opt) if got != nil { t.Errorf("rate.Reset.Time > now ListByOrg = %#v, want nil", got) } @@ -201,7 +201,7 @@ func TestRepositoriesService_ListAll(t *testing.T) { ctx := context.Background() opt := &RepositoryListAllOptions{1} - got, resp, err := client.Repositories.ListAll(ctx, opt) + got, _, err := client.Repositories.ListAll(ctx, opt) if err != nil { t.Errorf("Repositories.ListAll returned error: %v", err) } @@ -213,7 +213,7 @@ func TestRepositoriesService_ListAll(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.ListAll(ctx, &RepositoryListAllOptions{1}) + got, resp, err := client.Repositories.ListAll(ctx, &RepositoryListAllOptions{1}) if got != nil { t.Errorf("client.BaseURL.Path='' ListAll = %#v, want nil", got) } @@ -262,7 +262,7 @@ func TestRepositoriesService_Create_user(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.Create(ctx, "", input) + got, _, err := client.Repositories.Create(ctx, "", input) if err != nil { t.Errorf("Repositories.Create returned error: %v", err) } @@ -274,7 +274,7 @@ func TestRepositoriesService_Create_user(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.Create(ctx, "", input) + got, resp, err := client.Repositories.Create(ctx, "", input) if got != nil { t.Errorf("client.BaseURL.Path='' Create = %#v, want nil", got) } @@ -345,7 +345,7 @@ func TestRepositoriesService_Get(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.Get(ctx, "o", "r") + got, _, err := client.Repositories.Get(ctx, "o", "r") if err != nil { t.Errorf("Repositories.Get returned error: %v", err) } @@ -358,7 +358,7 @@ func TestRepositoriesService_Get(t *testing.T) { // Test s.client.Do failure client.BaseURL.Path = "/api-v3/" client.rateLimits[0].Reset.Time = time.Now().Add(10 * time.Minute) - got, resp, err = client.Repositories.Get(ctx, "o", "r") + got, resp, err := client.Repositories.Get(ctx, "o", "r") if got != nil { t.Errorf("rate.Reset.Time > now Get = %#v, want nil", got) } @@ -386,7 +386,7 @@ func TestRepositoriesService_GetCodeOfConduct(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.GetCodeOfConduct(ctx, "o", "r") + got, _, err := client.Repositories.GetCodeOfConduct(ctx, "o", "r") if err != nil { t.Errorf("Repositories.GetCodeOfConduct returned error: %v", err) } @@ -404,7 +404,7 @@ func TestRepositoriesService_GetCodeOfConduct(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.GetCodeOfConduct(ctx, "o", "r") + got, resp, err := client.Repositories.GetCodeOfConduct(ctx, "o", "r") if got != nil { t.Errorf("client.BaseURL.Path='' GetCodeOfConduct = %#v, want nil", got) } @@ -440,7 +440,7 @@ func TestRepositoriesService_GetByID(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.GetByID(ctx, 1) + got, _, err := client.Repositories.GetByID(ctx, 1) if err != nil { t.Fatalf("Repositories.GetByID returned error: %v", err) } @@ -452,7 +452,7 @@ func TestRepositoriesService_GetByID(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.GetByID(ctx, 1) + got, resp, err := client.Repositories.GetByID(ctx, 1) if got != nil { t.Errorf("client.BaseURL.Path='' GetByID = %#v, want nil", got) } @@ -497,7 +497,7 @@ func TestRepositoriesService_Edit(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.Edit(ctx, "o", "r", input) + got, _, err := client.Repositories.Edit(ctx, "o", "r", input) if err != nil { t.Errorf("Repositories.Edit returned error: %v", err) } @@ -510,7 +510,7 @@ func TestRepositoriesService_Edit(t *testing.T) { // Test s.client.Do failure client.BaseURL.Path = "/api-v3/" client.rateLimits[0].Reset.Time = time.Now().Add(10 * time.Minute) - got, resp, err = client.Repositories.Edit(ctx, "o", "r", input) + got, resp, err := client.Repositories.Edit(ctx, "o", "r", input) if got != nil { t.Errorf("rate.Reset.Time > now Edit = %#v, want nil", got) } @@ -531,14 +531,14 @@ func TestRepositoriesService_Delete(t *testing.T) { }) ctx := context.Background() - resp, err := client.Repositories.Delete(ctx, "o", "r") + _, err := client.Repositories.Delete(ctx, "o", "r") if err != nil { t.Errorf("Repositories.Delete returned error: %v", err) } // Test s.client.NewRequest failure client.BaseURL.Path = "" - resp, err = client.Repositories.Delete(ctx, "o", "r") + resp, err := client.Repositories.Delete(ctx, "o", "r") if resp != nil { t.Errorf("client.BaseURL.Path='' Delete resp = %#v, want nil", resp) } diff --git a/github/repos_traffic_test.go b/github/repos_traffic_test.go index 796544f3ce0..1479caaaf56 100644 --- a/github/repos_traffic_test.go +++ b/github/repos_traffic_test.go @@ -27,7 +27,7 @@ func TestRepositoriesService_ListTrafficReferrers(t *testing.T) { }]`) }) ctx := context.Background() - got, resp, err := client.Repositories.ListTrafficReferrers(ctx, "o", "r") + got, _, err := client.Repositories.ListTrafficReferrers(ctx, "o", "r") if err != nil { t.Errorf("Repositories.ListTrafficReferrers returned error: %+v", err) } @@ -43,7 +43,7 @@ func TestRepositoriesService_ListTrafficReferrers(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.ListTrafficReferrers(ctx, "o", "r") + got, resp, err := client.Repositories.ListTrafficReferrers(ctx, "o", "r") if got != nil { t.Errorf("client.BaseURL.Path='' ListTrafficReferrers = %#v, want nil", got) } @@ -83,7 +83,7 @@ func TestRepositoriesService_ListTrafficPaths(t *testing.T) { }]`) }) ctx := context.Background() - got, resp, err := client.Repositories.ListTrafficPaths(ctx, "o", "r") + got, _, err := client.Repositories.ListTrafficPaths(ctx, "o", "r") if err != nil { t.Errorf("Repositories.ListTrafficPaths returned error: %+v", err) } @@ -100,7 +100,7 @@ func TestRepositoriesService_ListTrafficPaths(t *testing.T) { // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.ListTrafficPaths(ctx, "o", "r") + got, resp, err := client.Repositories.ListTrafficPaths(ctx, "o", "r") if got != nil { t.Errorf("client.BaseURL.Path='' ListTrafficPaths = %#v, want nil", got) } @@ -142,7 +142,7 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.ListTrafficViews(ctx, "o", "r", nil) + got, _, err := client.Repositories.ListTrafficViews(ctx, "o", "r", nil) if err != nil { t.Errorf("Repositories.ListTrafficViews returned error: %+v", err) } @@ -162,14 +162,14 @@ func TestRepositoriesService_ListTrafficViews(t *testing.T) { } // Test addOptions failure - got, resp, err = client.Repositories.ListTrafficViews(ctx, "\n", "\n", &TrafficBreakdownOptions{}) + _, _, err = client.Repositories.ListTrafficViews(ctx, "\n", "\n", &TrafficBreakdownOptions{}) if err == nil { t.Error("bad options ListTrafficViews err = nil, want error") } // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.ListTrafficViews(ctx, "o", "r", nil) + got, resp, err := client.Repositories.ListTrafficViews(ctx, "o", "r", nil) if got != nil { t.Errorf("client.BaseURL.Path='' ListTrafficViews = %#v, want nil", got) } @@ -211,7 +211,7 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) { }) ctx := context.Background() - got, resp, err := client.Repositories.ListTrafficClones(ctx, "o", "r", nil) + got, _, err := client.Repositories.ListTrafficClones(ctx, "o", "r", nil) if err != nil { t.Errorf("Repositories.ListTrafficClones returned error: %+v", err) } @@ -231,14 +231,14 @@ func TestRepositoriesService_ListTrafficClones(t *testing.T) { } // Test addOptions failure - got, resp, err = client.Repositories.ListTrafficClones(ctx, "\n", "\n", &TrafficBreakdownOptions{}) + _, _, err = client.Repositories.ListTrafficClones(ctx, "\n", "\n", &TrafficBreakdownOptions{}) if err == nil { t.Error("bad options ListTrafficViews err = nil, want error") } // Test s.client.NewRequest failure client.BaseURL.Path = "" - got, resp, err = client.Repositories.ListTrafficClones(ctx, "o", "r", nil) + got, resp, err := client.Repositories.ListTrafficClones(ctx, "o", "r", nil) if got != nil { t.Errorf("client.BaseURL.Path='' ListTrafficClones = %#v, want nil", got) }