@@ -18,6 +18,7 @@ import (
18
18
"tailscale.com/tailcfg"
19
19
20
20
"cdr.dev/slog"
21
+ agentproto "github.com/coder/coder/v2/agent/proto"
21
22
"github.com/coder/coder/v2/codersdk"
22
23
"github.com/coder/coder/v2/codersdk/agentsdk"
23
24
drpcsdk "github.com/coder/coder/v2/codersdk/drpc"
@@ -48,6 +49,9 @@ func NewClient(t testing.TB,
48
49
}
49
50
err := proto .DRPCRegisterTailnet (mux , drpcService )
50
51
require .NoError (t , err )
52
+ fakeAAPI := NewFakeAgentAPI (t , logger )
53
+ err = agentproto .DRPCRegisterAgent (mux , fakeAAPI )
54
+ require .NoError (t , err )
51
55
server := drpcserver .NewWithOptions (mux , drpcserver.Options {
52
56
Log : func (err error ) {
53
57
if xerrors .Is (err , io .EOF ) {
@@ -64,22 +68,23 @@ func NewClient(t testing.TB,
64
68
statsChan : statsChan ,
65
69
coordinator : coordinator ,
66
70
server : server ,
71
+ fakeAgentAPI : fakeAAPI ,
67
72
derpMapUpdates : derpMapUpdates ,
68
73
}
69
74
}
70
75
71
76
type Client struct {
72
- t testing.TB
73
- logger slog.Logger
74
- agentID uuid.UUID
75
- manifest agentsdk.Manifest
76
- metadata map [string ]agentsdk.Metadata
77
- statsChan chan * agentsdk.Stats
78
- coordinator tailnet.Coordinator
79
- server * drpcserver.Server
80
- LastWorkspaceAgent func ()
81
- PatchWorkspaceLogs func () error
82
- GetServiceBannerFunc func () (codersdk. ServiceBannerConfig , error )
77
+ t testing.TB
78
+ logger slog.Logger
79
+ agentID uuid.UUID
80
+ manifest agentsdk.Manifest
81
+ metadata map [string ]agentsdk.Metadata
82
+ statsChan chan * agentsdk.Stats
83
+ coordinator tailnet.Coordinator
84
+ server * drpcserver.Server
85
+ fakeAgentAPI * FakeAgentAPI
86
+ LastWorkspaceAgent func ()
87
+ PatchWorkspaceLogs func () error
83
88
84
89
mu sync.Mutex // Protects following.
85
90
lifecycleStates []codersdk.WorkspaceAgentLifecycle
@@ -221,20 +226,7 @@ func (c *Client) PatchLogs(ctx context.Context, logs agentsdk.PatchLogs) error {
221
226
}
222
227
223
228
func (c * Client ) SetServiceBannerFunc (f func () (codersdk.ServiceBannerConfig , error )) {
224
- c .mu .Lock ()
225
- defer c .mu .Unlock ()
226
-
227
- c .GetServiceBannerFunc = f
228
- }
229
-
230
- func (c * Client ) GetServiceBanner (ctx context.Context ) (codersdk.ServiceBannerConfig , error ) {
231
- c .mu .Lock ()
232
- defer c .mu .Unlock ()
233
- c .logger .Debug (ctx , "get service banner" )
234
- if c .GetServiceBannerFunc != nil {
235
- return c .GetServiceBannerFunc ()
236
- }
237
- return codersdk.ServiceBannerConfig {}, nil
229
+ c .fakeAgentAPI .SetServiceBannerFunc (f )
238
230
}
239
231
240
232
func (c * Client ) PushDERPMapUpdate (update * tailcfg.DERPMap ) error {
@@ -254,3 +246,73 @@ type closeFunc func() error
254
246
func (c closeFunc ) Close () error {
255
247
return c ()
256
248
}
249
+
250
+ type FakeAgentAPI struct {
251
+ sync.Mutex
252
+ t testing.TB
253
+ logger slog.Logger
254
+
255
+ getServiceBannerFunc func () (codersdk.ServiceBannerConfig , error )
256
+ }
257
+
258
+ func (* FakeAgentAPI ) GetManifest (context.Context , * agentproto.GetManifestRequest ) (* agentproto.Manifest , error ) {
259
+ // TODO implement me
260
+ panic ("implement me" )
261
+ }
262
+
263
+ func (f * FakeAgentAPI ) SetServiceBannerFunc (fn func () (codersdk.ServiceBannerConfig , error )) {
264
+ f .Lock ()
265
+ defer f .Unlock ()
266
+ f .getServiceBannerFunc = fn
267
+ f .logger .Info (context .Background (), "updated ServiceBannerFunc" )
268
+ }
269
+
270
+ func (f * FakeAgentAPI ) GetServiceBanner (context.Context , * agentproto.GetServiceBannerRequest ) (* agentproto.ServiceBanner , error ) {
271
+ f .Lock ()
272
+ defer f .Unlock ()
273
+ if f .getServiceBannerFunc == nil {
274
+ return & agentproto.ServiceBanner {}, nil
275
+ }
276
+ sb , err := f .getServiceBannerFunc ()
277
+ if err != nil {
278
+ return nil , err
279
+ }
280
+ return agentproto .ServiceBannerFromSDK (sb ), nil
281
+ }
282
+
283
+ func (* FakeAgentAPI ) UpdateStats (context.Context , * agentproto.UpdateStatsRequest ) (* agentproto.UpdateStatsResponse , error ) {
284
+ // TODO implement me
285
+ panic ("implement me" )
286
+ }
287
+
288
+ func (* FakeAgentAPI ) UpdateLifecycle (context.Context , * agentproto.UpdateLifecycleRequest ) (* agentproto.Lifecycle , error ) {
289
+ // TODO implement me
290
+ panic ("implement me" )
291
+ }
292
+
293
+ func (* FakeAgentAPI ) BatchUpdateAppHealths (context.Context , * agentproto.BatchUpdateAppHealthRequest ) (* agentproto.BatchUpdateAppHealthResponse , error ) {
294
+ // TODO implement me
295
+ panic ("implement me" )
296
+ }
297
+
298
+ func (* FakeAgentAPI ) UpdateStartup (context.Context , * agentproto.UpdateStartupRequest ) (* agentproto.Startup , error ) {
299
+ // TODO implement me
300
+ panic ("implement me" )
301
+ }
302
+
303
+ func (* FakeAgentAPI ) BatchUpdateMetadata (context.Context , * agentproto.BatchUpdateMetadataRequest ) (* agentproto.BatchUpdateMetadataResponse , error ) {
304
+ // TODO implement me
305
+ panic ("implement me" )
306
+ }
307
+
308
+ func (* FakeAgentAPI ) BatchCreateLogs (context.Context , * agentproto.BatchCreateLogsRequest ) (* agentproto.BatchCreateLogsResponse , error ) {
309
+ // TODO implement me
310
+ panic ("implement me" )
311
+ }
312
+
313
+ func NewFakeAgentAPI (t testing.TB , logger slog.Logger ) * FakeAgentAPI {
314
+ return & FakeAgentAPI {
315
+ t : t ,
316
+ logger : logger .Named ("FakeAgentAPI" ),
317
+ }
318
+ }
0 commit comments