| 198 | } |
| 199 | |
| 200 | func TestPrompt_expiring_configure(t *testing.T) { |
| 201 | var gotMessage string |
| 202 | ios, _, _, stderr := iostreams.Test() |
| 203 | hc := &stubHelperConfig{helper: gitcredentials.Helper{Cmd: "osxkeychain"}} |
| 204 | f := GitCredentialFlow{ |
| 205 | IO: ios, |
| 206 | Prompter: &prompter.PrompterMock{ |
| 207 | SelectFunc: func(message, _ string, options []string) (int, error) { |
| 208 | gotMessage = message |
| 209 | return slices.Index(options, "Set up gh as your Git credential helper (recommended)"), nil |
| 210 | }, |
| 211 | }, |
| 212 | HelperConfig: hc, |
| 213 | } |
| 214 | |
| 215 | err := f.Prompt("github.com", true) |
| 216 | if err != nil { |
| 217 | t.Fatalf("Prompt() error = %v", err) |
| 218 | } |
| 219 | if !f.ShouldSetup() { |
| 220 | t.Error("ShouldSetup() = false, want true after choosing to configure gh") |
| 221 | } |
| 222 | if !slices.Contains(f.Scopes(), "workflow") { |
| 223 | t.Errorf("Scopes() = %v, want it to include workflow", f.Scopes()) |
| 224 | } |
| 225 | if !strings.Contains(gotMessage, "How would you like to proceed?") { |
| 226 | t.Errorf("prompt message = %q, want the short decision prompt", gotMessage) |
| 227 | } |
| 228 | if !strings.Contains(stderr.String(), "expiring token") { |
| 229 | t.Errorf("warning = %q, want it to explain the expiring token consequence", stderr.String()) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | func TestPrompt_expiring_decline(t *testing.T) { |
| 234 | ios, _, _, _ := iostreams.Test() |