MCPcopy Index your code
hub / github.com/coder/coder / TestExternalAuth

Function TestExternalAuth

cli/cliui/externalauth_test.go:18–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func 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}

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
ExternalAuthFunction · 0.92
WithContextMethod · 0.80
ExpectMatchContextMethod · 0.80
ContextMethod · 0.65
AttachMethod · 0.65
RunMethod · 0.65
StoreMethod · 0.45
StringMethod · 0.45
LoadMethod · 0.45
InvokeMethod · 0.45

Tested by

no test coverage detected