Merge pull request #2785 from n1lesh/auth-status-fail
Add fail message for non-existent hostname
This commit is contained in:
commit
188ff13d28
2 changed files with 19 additions and 0 deletions
|
|
@ -81,11 +81,13 @@ func statusRun(opts *StatusOptions) error {
|
|||
apiClient := api.NewClientFromHTTP(httpClient)
|
||||
|
||||
var failed bool
|
||||
var isHostnameFound bool
|
||||
|
||||
for _, hostname := range hostnames {
|
||||
if opts.Hostname != "" && opts.Hostname != hostname {
|
||||
continue
|
||||
}
|
||||
isHostnameFound = true
|
||||
|
||||
token, tokenSource, _ := cfg.GetWithSource(hostname, "oauth_token")
|
||||
tokenIsWriteable := cfg.CheckWriteable(hostname, "oauth_token") == nil
|
||||
|
|
@ -139,6 +141,12 @@ func statusRun(opts *StatusOptions) error {
|
|||
// not to since I wanted this command to be read-only.
|
||||
}
|
||||
|
||||
if !isHostnameFound {
|
||||
fmt.Fprintf(stderr,
|
||||
"Hostname %q not found among authenticated GitHub hosts\n", opts.Hostname)
|
||||
return cmdutil.SilentError
|
||||
}
|
||||
|
||||
for _, hostname := range hostnames {
|
||||
lines, ok := statusInfo[hostname]
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -190,6 +190,17 @@ func Test_statusRun(t *testing.T) {
|
|||
httpmock.StringResponse(`{"data":{"viewer":{"login":"tess"}}}`))
|
||||
},
|
||||
wantErrOut: regexp.MustCompile(`(?s)Token: xyz456.*Token: abc123`),
|
||||
}, {
|
||||
name: "missing hostname",
|
||||
opts: &StatusOptions{
|
||||
Hostname: "github.example.com",
|
||||
},
|
||||
cfg: func(c config.Config) {
|
||||
_ = c.Set("github.com", "oauth_token", "abc123")
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {},
|
||||
wantErrOut: regexp.MustCompile(`(?s)Hostname "github.example.com" not found among authenticated GitHub hosts`),
|
||||
wantErr: "SilentError",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue