@@ -18,6 +18,7 @@ import (
1818 "tailscale.com/tailcfg"
1919
2020 "cdr.dev/slog"
21+ agentproto "github.com/coder/coder/v2/agent/proto"
2122 "github.com/coder/coder/v2/codersdk"
2223 "github.com/coder/coder/v2/codersdk/agentsdk"
2324 drpcsdk "github.com/coder/coder/v2/codersdk/drpc"
@@ -48,6 +49,9 @@ func NewClient(t testing.TB,
4849 }
4950 err := proto .DRPCRegisterTailnet (mux , drpcService )
5051 require .NoError (t , err )
52+ fakeAAPI := NewFakeAgentAPI (t , logger )
53+ err = agentproto .DRPCRegisterAgent (mux , fakeAAPI )
54+ require .NoError (t , err )
5155 server := drpcserver .NewWithOptions (mux , drpcserver.Options {
5256 Log : func (err error ) {
5357 if xerrors .Is (err , io .EOF ) {
@@ -64,22 +68,23 @@ func NewClient(t testing.TB,
6468 statsChan : statsChan ,
6569 coordinator : coordinator ,
6670 server : server ,
71+ fakeAgentAPI : fakeAAPI ,
6772 derpMapUpdates : derpMapUpdates ,
6873 }
6974}
7075
7176type 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
8388
8489 mu sync.Mutex // Protects following.
8590 lifecycleStates []codersdk.WorkspaceAgentLifecycle
@@ -221,20 +226,7 @@ func (c *Client) PatchLogs(ctx context.Context, logs agentsdk.PatchLogs) error {
221226}
222227
223228func (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 )
238230}
239231
240232func (c * Client ) PushDERPMapUpdate (update * tailcfg.DERPMap ) error {
@@ -254,3 +246,73 @@ type closeFunc func() error
254246func (c closeFunc ) Close () error {
255247 return c ()
256248}
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