Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56c7ceb

Browse files
committed
implement fake agent api sub agent methods
1 parent934a222 commit56c7ceb

File tree

1 file changed

+81
-6
lines changed

1 file changed

+81
-6
lines changed

‎agent/agenttest/client.go

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ func (c *Client) GetConnectionReports() []*agentproto.ReportConnectionRequest {
163163
returnc.fakeAgentAPI.GetConnectionReports()
164164
}
165165

166+
func (c*Client)GetSubAgents() []*agentproto.SubAgent {
167+
returnc.fakeAgentAPI.GetSubAgents()
168+
}
169+
166170
typeFakeAgentAPIstruct {
167171
sync.Mutex
168172
t testing.TB
@@ -177,6 +181,7 @@ type FakeAgentAPI struct {
177181
metadatamap[string]agentsdk.Metadata
178182
timings []*agentproto.Timing
179183
connectionReports []*agentproto.ReportConnectionRequest
184+
subAgentsmap[uuid.UUID]*agentproto.SubAgent
180185

181186
getAnnouncementBannersFuncfunc() ([]codersdk.BannerConfig,error)
182187
getResourcesMonitoringConfigurationFuncfunc() (*agentproto.GetResourcesMonitoringConfigurationResponse,error)
@@ -365,16 +370,86 @@ func (f *FakeAgentAPI) GetConnectionReports() []*agentproto.ReportConnectionRequ
365370
returnslices.Clone(f.connectionReports)
366371
}
367372

368-
func (*FakeAgentAPI)CreateSubAgent(_ context.Context,_*agentproto.CreateSubAgentRequest) (*agentproto.CreateSubAgentResponse,error) {
369-
panic("unimplemented")
373+
func (f*FakeAgentAPI)CreateSubAgent(ctx context.Context,req*agentproto.CreateSubAgentRequest) (*agentproto.CreateSubAgentResponse,error) {
374+
f.Lock()
375+
deferf.Unlock()
376+
377+
f.logger.Debug(ctx,"create sub agent called",slog.F("req",req))
378+
379+
// Generate IDs for the new sub-agent.
380+
subAgentID:=uuid.New()
381+
authToken:=uuid.New()
382+
383+
// Create the sub-agent proto object.
384+
subAgent:=&agentproto.SubAgent{
385+
Id:subAgentID[:],
386+
Name:req.Name,
387+
AuthToken:authToken[:],
388+
}
389+
390+
// Store the sub-agent in our map.
391+
iff.subAgents==nil {
392+
f.subAgents=make(map[uuid.UUID]*agentproto.SubAgent)
393+
}
394+
f.subAgents[subAgentID]=subAgent
395+
396+
// For a fake implementation, we don't create workspace apps.
397+
// Real implementations would handle req.Apps here.
398+
return&agentproto.CreateSubAgentResponse{
399+
Agent:subAgent,
400+
AppCreationErrors:nil,
401+
},nil
402+
}
403+
404+
func (f*FakeAgentAPI)DeleteSubAgent(ctx context.Context,req*agentproto.DeleteSubAgentRequest) (*agentproto.DeleteSubAgentResponse,error) {
405+
f.Lock()
406+
deferf.Unlock()
407+
408+
f.logger.Debug(ctx,"delete sub agent called",slog.F("req",req))
409+
410+
subAgentID,err:=uuid.FromBytes(req.Id)
411+
iferr!=nil {
412+
returnnil,err
413+
}
414+
415+
// Remove the sub-agent from our map.
416+
iff.subAgents!=nil {
417+
delete(f.subAgents,subAgentID)
418+
}
419+
420+
return&agentproto.DeleteSubAgentResponse{},nil
370421
}
371422

372-
func (*FakeAgentAPI)DeleteSubAgent(_ context.Context,_*agentproto.DeleteSubAgentRequest) (*agentproto.DeleteSubAgentResponse,error) {
373-
panic("unimplemented")
423+
func (f*FakeAgentAPI)ListSubAgents(ctx context.Context,req*agentproto.ListSubAgentsRequest) (*agentproto.ListSubAgentsResponse,error) {
424+
f.Lock()
425+
deferf.Unlock()
426+
427+
f.logger.Debug(ctx,"list sub agents called",slog.F("req",req))
428+
429+
varagents []*agentproto.SubAgent
430+
iff.subAgents!=nil {
431+
agents=make([]*agentproto.SubAgent,0,len(f.subAgents))
432+
for_,agent:=rangef.subAgents {
433+
agents=append(agents,agent)
434+
}
435+
}
436+
437+
return&agentproto.ListSubAgentsResponse{
438+
Agents:agents,
439+
},nil
374440
}
375441

376-
func (*FakeAgentAPI)ListSubAgents(_ context.Context,_*agentproto.ListSubAgentsRequest) (*agentproto.ListSubAgentsResponse,error) {
377-
panic("unimplemented")
442+
func (f*FakeAgentAPI)GetSubAgents() []*agentproto.SubAgent {
443+
f.Lock()
444+
deferf.Unlock()
445+
varagents []*agentproto.SubAgent
446+
iff.subAgents!=nil {
447+
agents=make([]*agentproto.SubAgent,0,len(f.subAgents))
448+
for_,agent:=rangef.subAgents {
449+
agents=append(agents,agent)
450+
}
451+
}
452+
returnagents
378453
}
379454

380455
funcNewFakeAgentAPI(t testing.TB,logger slog.Logger,manifest*agentproto.Manifest,statsChchan*agentproto.Stats)*FakeAgentAPI {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp