Skip to content

Some *Response return values are not covered by tests #3953

@alexandear

Description

@alexandear

A few exported methods return *Response as the second result, but this value is never exercised by tests.

Based on the latest commit, the following methods are affected:

github/pulls.go:362:123: (*PullRequestsService).Edit
github/repos_releases.go:456:153: (*RepositoriesService).UploadReleaseAsset
github/search.go:81:122: (*SearchService).Repositories
github/search.go:119:110: (*SearchService).Topicsfunc
github/search.go:156:112: (*SearchService).Commits
github/search.go:178:110: (*SearchService).Issues
github/search.go:200:108: (*SearchService).Users
github/search.go:255:106: (*SearchService).Code
github/search.go:292:124: (*SearchService).Labels

This was discovered using the unparam linter, which reports result 1 (*github.com/google/go-github/v82/github.Response) is never used:

Details

❯ ./script/lint.sh
linting .
github/pulls.go:362:123: (*PullRequestsService).Edit - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *PullRequestsService) Edit(ctx context.Context, owner, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) {
                                                                                                                          ^
github/repos_releases.go:456:153: (*RepositoriesService).UploadReleaseAsset - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *RepositoriesService) UploadReleaseAsset(ctx context.Context, owner, repo string, id int64, opts *UploadOptions, file *os.File) (*ReleaseAsset, *Response, error) {
                                                                                                                                                        ^
github/search.go:81:122: (*SearchService).Repositories - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Repositories(ctx context.Context, query string, opts *SearchOptions) (*RepositoriesSearchResult, *Response, error) {
                                                                                                                         ^
github/search.go:119:110: (*SearchService).Topics - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Topics(ctx context.Context, query string, opts *SearchOptions) (*TopicsSearchResult, *Response, error) {
                                                                                                             ^
github/search.go:156:112: (*SearchService).Commits - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Commits(ctx context.Context, query string, opts *SearchOptions) (*CommitsSearchResult, *Response, error) {
                                                                                                               ^
github/search.go:178:110: (*SearchService).Issues - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Issues(ctx context.Context, query string, opts *SearchOptions) (*IssuesSearchResult, *Response, error) {
                                                                                                             ^
github/search.go:200:108: (*SearchService).Users - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Users(ctx context.Context, query string, opts *SearchOptions) (*UsersSearchResult, *Response, error) {
                                                                                                           ^
github/search.go:255:106: (*SearchService).Code - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Code(ctx context.Context, query string, opts *SearchOptions) (*CodeSearchResult, *Response, error) {
                                                                                                         ^
github/search.go:292:124: (*SearchService).Labels - result 1 (*github.com/google/go-github/v82/github.Response) is never used (unparam)
func (s *SearchService) Labels(ctx context.Context, repoID int64, query string, opts *SearchOptions) (*LabelsSearchResult, *Response, error) {
                                                                                                                           ^
9 issues:
* unparam: 9
failed linting .
linting example
/Users/alexandear/src/github.com/google/go-github/example
0 issues.
linting scrape
/Users/alexandear/src/github.com/google/go-github/scrape
scrape/apps.go:139:61: (*Client).CreateApp - result 0 (*net/http.Response) is never used (unparam)
func (c *Client) CreateApp(m *AppManifest, orgName string) (*http.Response, error) {
                                                            ^
1 issues:
* unparam: 1
failed linting scrape
linting tools
/Users/alexandear/src/github.com/google/go-github/tools
0 issues.
linting tools/fmtpercentv
/Users/alexandear/src/github.com/google/go-github/tools/fmtpercentv
0 issues.
linting tools/sliceofpointers
/Users/alexandear/src/github.com/google/go-github/tools/sliceofpointers
0 issues.
linting tools/structfield
/Users/alexandear/src/github.com/google/go-github/tools/structfield
0 issues.

Suggested fix is to add tests using the existing helper testNewRequestAndDoFailure.

Proposed steps

  1. Enable check-exported: true in linters.settings.unparam in .golangci.yml.
  2. Run ./script/lint.sh - 9 issues are reported in the github package.
  3. Fix the listed methods by adding tests that assert the returned *Response via testNewRequestAndDoFailure.
  4. Fix remaining unparam issues in other packages.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions