Replace "GitHub Enterprise Server" with "other" in gh auth login prompt

This change is meant to better support the login flow for other customers
besides GitHub Enterprise Server customers that use the same login flow
as GHES.
This commit is contained in:
Tyler McGoffin 2024-09-19 14:52:16 -07:00
parent d451a4341b
commit 5dd5246307
2 changed files with 51 additions and 3 deletions

View file

@ -222,7 +222,7 @@ func loginRun(opts *LoginOptions) error {
}
func promptForHostname(opts *LoginOptions) (string, error) {
options := []string{"GitHub.com", "GitHub Enterprise Server"}
options := []string{"GitHub.com", "other"}
hostType, err := opts.Prompter.Select(
"What account do you want to log into?",
options[0],

View file

@ -2,6 +2,7 @@ package login
import (
"bytes"
"fmt"
"net/http"
"regexp"
"runtime"
@ -546,7 +547,7 @@ func Test_loginRun_Survey(t *testing.T) {
wantErrOut: regexp.MustCompile("Tip: you can generate a Personal Access Token here https://rebecca.chambers/settings/tokens"),
},
{
name: "choose enterprise",
name: "choose other",
wantHosts: heredoc.Doc(`
brad.vickers:
users:
@ -564,7 +565,7 @@ func Test_loginRun_Survey(t *testing.T) {
pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) {
switch prompt {
case "What account do you want to log into?":
return prompter.IndexFor(opts, "GitHub Enterprise Server")
return prompter.IndexFor(opts, "other")
case "What is your preferred protocol for Git operations on this host?":
return prompter.IndexFor(opts, "HTTPS")
case "How would you like to authenticate GitHub CLI?":
@ -803,3 +804,50 @@ func Test_loginRun_Survey(t *testing.T) {
})
}
}
func Test_promptForHostname(t *testing.T) {
tests := []struct {
name string
options []string
selectedIndex int
// This is so we can test that the options in the function don't change
expectedSelection string
inputHostname string
expect string
}{
{
name: "select GitHub.com",
selectedIndex: 0,
expectedSelection: "GitHub.com",
expect: "github.com",
},
{
name: "select other",
selectedIndex: 1,
expectedSelection: "other",
inputHostname: "github.enterprise.com",
expect: "github.enterprise.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
promptMock := &prompter.PrompterMock{
SelectFunc: func(_ string, _ string, options []string) (int, error) {
if options[tt.selectedIndex] != tt.expectedSelection {
return 0, fmt.Errorf("expected %s at index %d, but got %s", tt.expectedSelection, tt.selectedIndex, options[tt.selectedIndex])
}
return tt.selectedIndex, nil
},
InputHostnameFunc: func() (string, error) {
return tt.inputHostname, nil
},
}
opts := &LoginOptions{
Prompter: promptMock,
}
hostname, err := promptForHostname(opts)
require.NoError(t, err)
require.Equal(t, tt.expect, hostname)
})
}
}