(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestExternalAuth(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 22 | defer cancel() |
| 23 | |
| 24 | ptty := ptytest.New(t) |
| 25 | cmd := &serpent.Command{ |
| 26 | Handler: func(inv *serpent.Invocation) error { |
| 27 | var fetched atomic.Bool |
| 28 | return cliui.ExternalAuth(inv.Context(), inv.Stdout, cliui.ExternalAuthOptions{ |
| 29 | Fetch: func(ctx context.Context) ([]codersdk.TemplateVersionExternalAuth, error) { |
| 30 | defer fetched.Store(true) |
| 31 | return []codersdk.TemplateVersionExternalAuth{{ |
| 32 | ID: "github", |
| 33 | DisplayName: "GitHub", |
| 34 | Type: codersdk.EnhancedExternalAuthProviderGitHub.String(), |
| 35 | Authenticated: fetched.Load(), |
| 36 | AuthenticateURL: "https://example.com/gitauth/github", |
| 37 | }}, nil |
| 38 | }, |
| 39 | FetchInterval: time.Millisecond, |
| 40 | }) |
| 41 | }, |
| 42 | } |
| 43 | |
| 44 | inv := cmd.Invoke().WithContext(ctx) |
| 45 | |
| 46 | ptty.Attach(inv) |
| 47 | done := make(chan struct{}) |
| 48 | go func() { |
| 49 | defer close(done) |
| 50 | err := inv.Run() |
| 51 | assert.NoError(t, err) |
| 52 | }() |
| 53 | ptty.ExpectMatchContext(ctx, "You must authenticate with") |
| 54 | ptty.ExpectMatchContext(ctx, "https://example.com/gitauth/github") |
| 55 | ptty.ExpectMatchContext(ctx, "Successfully authenticated with GitHub") |
| 56 | <-done |
| 57 | } |
nothing calls this directly
no test coverage detected