(t *testing.T)
| 72 | } |
| 73 | |
| 74 | func TestAuthenticateURLElicitation(t *testing.T) { |
| 75 | f := newFakeGitHub(t) |
| 76 | m := newManager(t, f) |
| 77 | m.openURL = func(string) error { return errors.New("no browser") } |
| 78 | |
| 79 | prompter := &fakePrompter{ |
| 80 | urlCapable: true, |
| 81 | onURL: func(_ context.Context, p Prompt) error { |
| 82 | return browserGet(p.URL) // user opens the URL and authorizes |
| 83 | }, |
| 84 | } |
| 85 | |
| 86 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 87 | defer cancel() |
| 88 | |
| 89 | out, err := m.Authenticate(ctx, prompter) |
| 90 | require.NoError(t, err) |
| 91 | assert.Nil(t, out) |
| 92 | assert.Equal(t, "gho_access", m.AccessToken()) |
| 93 | |
| 94 | prompter.mu.Lock() |
| 95 | defer prompter.mu.Unlock() |
| 96 | require.Len(t, prompter.urlCalls, 1) |
| 97 | assert.NotEmpty(t, prompter.urlCalls[0].URL) |
| 98 | } |
| 99 | |
| 100 | func TestAuthenticateDeclinedPromptFails(t *testing.T) { |
| 101 | f := newFakeGitHub(t) |
nothing calls this directly
no test coverage detected