@@ -21,27 +21,27 @@ import (
21
21
"github.com/coder/coder/testutil"
22
22
)
23
23
24
- //nolint:tparallel,paralleltest // Subtests require setup that must not be done in parallel.
25
- func TestPortForward (t * testing.T ) {
26
- t .Run ("None" , func (t * testing.T ) {
27
- t .Parallel ()
24
+ func TestPortForward_None (t * testing.T ) {
25
+ t .Parallel ()
28
26
29
- client := coderdtest .New (t , nil )
30
- _ = coderdtest .CreateFirstUser (t , client )
27
+ client := coderdtest .New (t , nil )
28
+ _ = coderdtest .CreateFirstUser (t , client )
31
29
32
- inv , root := clitest .New (t , "port-forward" , "blah" )
33
- clitest .SetupConfig (t , client , root )
34
- pty := ptytest .New (t ).Attach (inv )
35
- inv .Stderr = pty .Output ()
30
+ inv , root := clitest .New (t , "port-forward" , "blah" )
31
+ clitest .SetupConfig (t , client , root )
32
+ pty := ptytest .New (t ).Attach (inv )
33
+ inv .Stderr = pty .Output ()
36
34
37
- err := inv .Run ()
38
- require .Error (t , err )
39
- require .ErrorContains (t , err , "no port-forwards" )
35
+ err := inv .Run ()
36
+ require .Error (t , err )
37
+ require .ErrorContains (t , err , "no port-forwards" )
40
38
41
- // Check that the help was printed.
42
- pty .ExpectMatch ("port-forward <workspace>" )
43
- })
39
+ // Check that the help was printed.
40
+ pty .ExpectMatch ("port-forward <workspace>" )
41
+ }
44
42
43
+ //nolint:tparallel,paralleltest // Subtests require setup that must not be done in parallel.
44
+ func TestPortForward (t * testing.T ) {
45
45
cases := []struct {
46
46
name string
47
47
network string
@@ -134,13 +134,13 @@ func TestPortForward(t *testing.T) {
134
134
inv .Stdin = pty .Input ()
135
135
inv .Stdout = pty .Output ()
136
136
inv .Stderr = pty .Output ()
137
- ctx , cancel := context .WithCancel (context .Background ())
137
+ ctx , cancel := context .WithTimeout (context .Background (), testutil . WaitLong )
138
138
defer cancel ()
139
139
errC := make (chan error )
140
140
go func () {
141
141
errC <- inv .WithContext (ctx ).Run ()
142
142
}()
143
- pty .ExpectMatch ( "Ready!" )
143
+ pty .ExpectMatchContext ( ctx , "Ready!" )
144
144
145
145
t .Parallel () // Port is reserved, enable parallel execution.
146
146
@@ -181,13 +181,13 @@ func TestPortForward(t *testing.T) {
181
181
inv .Stdin = pty .Input ()
182
182
inv .Stdout = pty .Output ()
183
183
inv .Stderr = pty .Output ()
184
- ctx , cancel := context .WithCancel (context .Background ())
184
+ ctx , cancel := context .WithTimeout (context .Background (), testutil . WaitLong )
185
185
defer cancel ()
186
186
errC := make (chan error )
187
187
go func () {
188
188
errC <- inv .WithContext (ctx ).Run ()
189
189
}()
190
- pty .ExpectMatch ( "Ready!" )
190
+ pty .ExpectMatchContext ( ctx , "Ready!" )
191
191
192
192
t .Parallel () // Port is reserved, enable parallel execution.
193
193
@@ -234,13 +234,13 @@ func TestPortForward(t *testing.T) {
234
234
clitest .SetupConfig (t , client , root )
235
235
pty := ptytest .New (t ).Attach (inv )
236
236
inv .Stderr = pty .Output ()
237
- ctx , cancel := context .WithCancel (context .Background ())
237
+ ctx , cancel := context .WithTimeout (context .Background (), testutil . WaitLong )
238
238
defer cancel ()
239
239
errC := make (chan error )
240
240
go func () {
241
241
errC <- inv .WithContext (ctx ).Run ()
242
242
}()
243
- pty .ExpectMatch ( "Ready!" )
243
+ pty .ExpectMatchContext ( ctx , "Ready!" )
244
244
245
245
t .Parallel () // Port is reserved, enable parallel execution.
246
246
0 commit comments