@@ -17,53 +17,99 @@ func TestLogout(t *testing.T) {
17
17
t .Run ("Logout" , func (t * testing.T ) {
18
18
t .Parallel ()
19
19
20
- config := login (t )
20
+ pty := ptytest .New (t )
21
+ config := login (t , pty )
21
22
22
23
// ensure session files exist
23
24
assert .FileExists (t , string (config .URL ()))
24
25
assert .FileExists (t , string (config .Session ()))
25
26
27
+ logoutChan := make (chan struct {})
26
28
logout , _ := clitest .New (t , "logout" , "--global-config" , string (config ))
27
- err := logout .Execute ()
28
- assert .NoError (t , err )
29
- assert .NoFileExists (t , string (config .URL ()))
30
- assert .NoFileExists (t , string (config .Session ()))
29
+ logout .SetIn (pty .Input ())
30
+ logout .SetOut (pty .Output ())
31
+
32
+ go func () {
33
+ defer close (logoutChan )
34
+ err := logout .Execute ()
35
+ assert .NoError (t , err )
36
+ assert .NoFileExists (t , string (config .URL ()))
37
+ assert .NoFileExists (t , string (config .Session ()))
38
+ }()
39
+
40
+ pty .ExpectMatch ("Successfully logged out" )
41
+ <- logoutChan
31
42
})
32
43
t .Run ("NoURLFile" , func (t * testing.T ) {
33
44
t .Parallel ()
34
45
35
- logout , _ := clitest .New (t , "logout" )
46
+ pty := ptytest .New (t )
47
+ config := login (t , pty )
48
+
49
+ // ensure session files exist
50
+ assert .FileExists (t , string (config .URL ()))
51
+ assert .FileExists (t , string (config .Session ()))
52
+
53
+ os .RemoveAll (string (config .URL ()))
36
54
37
- err := logout .Execute ()
38
- assert .EqualError (t , err , "You are not logged in. Try logging in using 'coder login <url>'." )
55
+ logoutChan := make (chan struct {})
56
+ logout , _ := clitest .New (t , "logout" , "--global-config" , string (config ))
57
+
58
+ logout .SetIn (pty .Input ())
59
+ logout .SetOut (pty .Output ())
60
+
61
+ go func () {
62
+ defer close (logoutChan )
63
+ err := logout .Execute ()
64
+ assert .NoError (t , err )
65
+ assert .NoFileExists (t , string (config .URL ()))
66
+ assert .NoFileExists (t , string (config .Session ()))
67
+ }()
68
+
69
+ pty .ExpectMatch ("You are not logged in. Try logging in using 'coder login <url>'." )
70
+ pty .ExpectMatch ("Successfully logged out" )
71
+ <- logoutChan
39
72
})
40
73
t .Run ("NoSessionFile" , func (t * testing.T ) {
41
74
t .Parallel ()
42
75
43
- config := login (t )
76
+ pty := ptytest .New (t )
77
+ config := login (t , pty )
44
78
45
79
// ensure session files exist
46
80
assert .FileExists (t , string (config .URL ()))
47
81
assert .FileExists (t , string (config .Session ()))
48
82
49
83
os .RemoveAll (string (config .Session ()))
50
84
85
+ logoutChan := make (chan struct {})
51
86
logout , _ := clitest .New (t , "logout" , "--global-config" , string (config ))
52
87
53
- err := logout .Execute ()
54
- assert .EqualError (t , err , "You are not logged in. Try logging in using 'coder login <url>'." )
88
+ logout .SetIn (pty .Input ())
89
+ logout .SetOut (pty .Output ())
90
+
91
+ go func () {
92
+ defer close (logoutChan )
93
+ err := logout .Execute ()
94
+ assert .NoError (t , err )
95
+ assert .NoFileExists (t , string (config .URL ()))
96
+ assert .NoFileExists (t , string (config .Session ()))
97
+ }()
98
+
99
+ pty .ExpectMatch ("You are not logged in. Try logging in using 'coder login <url>'." )
100
+ pty .ExpectMatch ("Successfully logged out" )
101
+ <- logoutChan
55
102
})
56
103
}
57
104
58
- func login (t * testing.T ) config.Root {
105
+ func login (t * testing.T , pty * ptytest. PTY ) config.Root {
59
106
t .Helper ()
60
107
61
108
client := coderdtest .New (t , nil )
62
109
coderdtest .CreateFirstUser (t , client )
63
110
64
111
doneChan := make (chan struct {})
65
112
root , cfg := clitest .New (t , "login" , "--force-tty" , client .URL .String (), "--no-open" )
66
- pty := ptytest .New (t )
67
113
root .SetIn (pty .Input ())
68
114
root .SetOut (pty .Output ())
69
115
go func () {
0 commit comments