Skip to content

Commit f3fcaf6

Browse files
committed
Fix error message text & add test case
1 parent 2f5ffbd commit f3fcaf6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/cmd/auth/status/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func statusRun(opts *StatusOptions) error {
143143

144144
if !isHostnameFound {
145145
fmt.Fprintf(stderr,
146-
"You are not logged into any GitHub hosts. Run %s to authenticate.\n", cs.Bold(fmt.Sprintf("gh auth login -h %s", opts.Hostname)))
146+
"Hostname %q not found among authenticated GitHub hosts\n", opts.Hostname)
147147
return cmdutil.SilentError
148148
}
149149

pkg/cmd/auth/status/status_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ func Test_statusRun(t *testing.T) {
190190
httpmock.StringResponse(`{"data":{"viewer":{"login":"tess"}}}`))
191191
},
192192
wantErrOut: regexp.MustCompile(`(?s)Token: xyz456.*Token: abc123`),
193+
}, {
194+
name: "missing hostname",
195+
opts: &StatusOptions{
196+
Hostname: "github.example.com",
197+
},
198+
cfg: func(c config.Config) {
199+
_ = c.Set("github.com", "oauth_token", "abc123")
200+
},
201+
httpStubs: func(reg *httpmock.Registry) {},
202+
wantErrOut: regexp.MustCompile(`(?s)Hostname "github.example.com" not found among authenticated GitHub hosts`),
203+
wantErr: regexp.MustCompile(``),
193204
},
194205
}
195206

@@ -241,9 +252,9 @@ func Test_statusRun(t *testing.T) {
241252
if tt.wantErr != nil {
242253
assert.True(t, tt.wantErr.MatchString(err.Error()))
243254
return
244-
} else {
245-
t.Fatalf("unexpected error: %s", err)
246255
}
256+
257+
t.Fatalf("unexpected error: %s", err)
247258
}
248259

249260
if tt.wantErrOut == nil {

0 commit comments

Comments
 (0)