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

Function TestLogout

cli/logout_test.go:18–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestLogout(t *testing.T) {
19 t.Parallel()
20 t.Run("Logout", func(t *testing.T) {
21 t.Parallel()
22
23 pty := ptytest.New(t)
24 config := login(t, pty)
25
26 // Ensure session files exist.
27 require.FileExists(t, string(config.URL()))
28 require.FileExists(t, string(config.Session()))
29
30 logoutChan := make(chan struct{})
31 logout, _ := clitest.New(t, "logout", "--global-config", string(config))
32 logout.Stdin = pty.Input()
33 logout.Stdout = pty.Output()
34
35 go func() {
36 defer close(logoutChan)
37 err := logout.Run()
38 assert.NoError(t, err)
39 assert.NoFileExists(t, string(config.URL()))
40 assert.NoFileExists(t, string(config.Session()))
41 }()
42
43 pty.ExpectMatch("Are you sure you want to log out?")
44 pty.WriteLine("yes")
45 pty.ExpectMatch("You are no longer logged in. You can log in using 'coder login <url>'.")
46 <-logoutChan
47 })
48 t.Run("SkipPrompt", func(t *testing.T) {
49 t.Parallel()
50
51 pty := ptytest.New(t)
52 config := login(t, pty)
53
54 // Ensure session files exist.
55 require.FileExists(t, string(config.URL()))
56 require.FileExists(t, string(config.Session()))
57
58 logoutChan := make(chan struct{})
59 logout, _ := clitest.New(t, "logout", "--global-config", string(config), "-y")
60 logout.Stdin = pty.Input()
61 logout.Stdout = pty.Output()
62
63 go func() {
64 defer close(logoutChan)
65 err := logout.Run()
66 assert.NoError(t, err)
67 assert.NoFileExists(t, string(config.URL()))
68 assert.NoFileExists(t, string(config.Session()))
69 }()
70
71 pty.ExpectMatch("You are no longer logged in. You can log in using 'coder login <url>'.")
72 <-logoutChan
73 })
74 t.Run("NoURLFile", func(t *testing.T) {
75 t.Parallel()

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
NewFunction · 0.92
WriteLineMethod · 0.80
loginFunction · 0.70
RunMethod · 0.65
SessionMethod · 0.65
InputMethod · 0.65
OutputMethod · 0.65
RemoveMethod · 0.65
CloseMethod · 0.65
LogfMethod · 0.65
URLMethod · 0.45

Tested by

no test coverage detected