diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index 9e27f28ac..2eded806e 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -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], diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index d53dd3f0b..555606d56 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -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) + }) + } +}