Merge pull request #7241 from cli/repo-list-owner-test

repo list: add test for invalid owner error
This commit is contained in:
Nate Smith 2023-03-29 16:13:41 -07:00 committed by GitHub
commit 6e1693eaf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -452,3 +452,40 @@ func TestRepoList_noVisibilityField(t *testing.T) {
assert.Equal(t, "", stderr.String())
assert.Equal(t, "", stdout.String())
}
func TestRepoList_invalidOwner(t *testing.T) {
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(false)
ios.SetStdinTTY(false)
ios.SetStderrTTY(false)
reg := &httpmock.Registry{}
defer reg.Verify(t)
reg.Register(
httpmock.GraphQL(`query RepositoryList\b`),
httpmock.StringResponse(`{ "data": { "repositoryOwner": null } }`),
)
opts := ListOptions{
Owner: "nonexist",
IO: ios,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
},
Config: func() (config.Config, error) {
return config.NewBlankConfig(), nil
},
Now: func() time.Time {
t, _ := time.Parse(time.RFC822, "19 Feb 21 15:00 UTC")
return t
},
Limit: 30,
Detector: &fd.DisabledDetectorMock{},
}
err := listRun(&opts)
assert.EqualError(t, err, `the owner handle "nonexist" was not recognized as either a GitHub user or an organization`)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "", stdout.String())
}