Skip to content

Add fail message for non-existent hostname#2785

Merged
samcoe merged 4 commits intocli:trunkfrom
n1lesh:auth-status-fail
Jan 22, 2021
Merged

Add fail message for non-existent hostname#2785
samcoe merged 4 commits intocli:trunkfrom
n1lesh:auth-status-fail

Conversation

@n1lesh
Copy link
Contributor

@n1lesh n1lesh commented Jan 15, 2021

Fixes #2775.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! The error message text needs changing, though.

Did you consider also making a test in status_test.go?


if !isHostnameFound {
fmt.Fprintf(stderr,
"You are not logged into any GitHub hosts. Run %s to authenticate.\n", cs.Bold(fmt.Sprintf("gh auth login -h %s", opts.Hostname)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already print this message above:

if len(hostnames) == 0 || err != nil {
fmt.Fprintf(stderr,
"You are not logged into any GitHub hosts. Run %s to authenticate.\n", cs.Bold("gh auth login"))
return cmdutil.SilentError

The message you added here isn't accurate for the condition we're testing. The issue you've set to fix is to warn that a hostname passed via the -h argument wasn't found. How about something like this?

"Hostname %q not found among authenticated GitHub hosts"

Copy link
Contributor Author

@n1lesh n1lesh Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mislav It seems that the code in status_test.go silently ignores the stderr message in favour of wantErr.

assert.Equal(t, tt.wantErr == nil, err == nil)
if err != nil {
if tt.wantErr != nil {
assert.True(t, tt.wantErr.MatchString(err.Error()))
return

Since we return SilentError we have to make wantErr non-nil, and that forces condition on L241 to occur, thus pre-maturely returning, avoiding a check on wantErrOut. Any suggestions around this?

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Thank you.

@vilmibm vilmibm assigned vilmibm and samcoe and unassigned vilmibm Jan 20, 2021
@vilmibm
Copy link
Contributor

vilmibm commented Jan 20, 2021

@samcoe to fix conflicts and merge

@samcoe samcoe merged commit 188ff13 into cli:trunk Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh auth status -h <enterprise host> passes if host not yet configured

5 participants