@@ -46,7 +46,6 @@ func TestAgent(t *testing.T) {
46
46
func (_ context.Context , agent * codersdk.WorkspaceAgent , logs chan []codersdk.WorkspaceAgentStartupLog ) error {
47
47
agent .Status = codersdk .WorkspaceAgentConnected
48
48
agent .FirstConnectedAt = ptr .Ref (time .Now ())
49
- close (logs )
50
49
return nil
51
50
},
52
51
},
@@ -79,7 +78,6 @@ func TestAgent(t *testing.T) {
79
78
agent .FirstConnectedAt = ptr .Ref (time .Now ())
80
79
agent .LifecycleState = codersdk .WorkspaceAgentLifecycleReady
81
80
agent .ReadyAt = ptr .Ref (time .Now ())
82
- close (logs )
83
81
return nil
84
82
},
85
83
},
@@ -113,10 +111,6 @@ func TestAgent(t *testing.T) {
113
111
agent .LastConnectedAt = ptr .Ref (time .Now ())
114
112
return nil
115
113
},
116
- func (_ context.Context , _ * codersdk.WorkspaceAgent , logs chan []codersdk.WorkspaceAgentStartupLog ) error {
117
- close (logs )
118
- return nil
119
- },
120
114
},
121
115
want : []string {
122
116
"⧗ The workspace agent lost connection" ,
@@ -154,7 +148,6 @@ func TestAgent(t *testing.T) {
154
148
Output : "Bye now" ,
155
149
},
156
150
}
157
- close (logs )
158
151
return nil
159
152
},
160
153
},
@@ -184,7 +177,6 @@ func TestAgent(t *testing.T) {
184
177
Output : "Hello world" ,
185
178
},
186
179
}
187
- close (logs )
188
180
return nil
189
181
},
190
182
},
@@ -205,7 +197,6 @@ func TestAgent(t *testing.T) {
205
197
func (_ context.Context , agent * codersdk.WorkspaceAgent , logs chan []codersdk.WorkspaceAgentStartupLog ) error {
206
198
agent .Status = codersdk .WorkspaceAgentDisconnected
207
199
agent .LifecycleState = codersdk .WorkspaceAgentLifecycleOff
208
- close (logs )
209
200
return nil
210
201
},
211
202
},
@@ -234,7 +225,6 @@ func TestAgent(t *testing.T) {
234
225
func (_ context.Context , agent * codersdk.WorkspaceAgent , logs chan []codersdk.WorkspaceAgentStartupLog ) error {
235
226
agent .ReadyAt = ptr .Ref (time .Now ())
236
227
agent .LifecycleState = codersdk .WorkspaceAgentLifecycleShuttingDown
237
- close (logs )
238
228
return nil
239
229
},
240
230
},
@@ -316,8 +306,21 @@ func TestAgent(t *testing.T) {
316
306
}
317
307
return agent , err
318
308
}
319
- tc .opts .FetchLogs = func (_ context.Context , _ uuid.UUID , _ int64 , _ bool ) (<- chan []codersdk.WorkspaceAgentStartupLog , io.Closer , error ) {
320
- return logs , closeFunc (func () error { return nil }), nil
309
+ tc .opts .FetchLogs = func (ctx context.Context , _ uuid.UUID , _ int64 , follow bool ) (<- chan []codersdk.WorkspaceAgentStartupLog , io.Closer , error ) {
310
+ if follow {
311
+ return logs , closeFunc (func () error { return nil }), nil
312
+ }
313
+
314
+ fetchLogs := make (chan []codersdk.WorkspaceAgentStartupLog , 1 )
315
+ select {
316
+ case <- ctx .Done ():
317
+ return nil , nil , ctx .Err ()
318
+ case l := <- logs :
319
+ fetchLogs <- l
320
+ default :
321
+ }
322
+ close (fetchLogs )
323
+ return fetchLogs , closeFunc (func () error { return nil }), nil
321
324
}
322
325
err := cliui .Agent (inv .Context (), & buf , uuid .Nil , tc .opts )
323
326
return err
0 commit comments