Skip to content

Commit 05e50d7

Browse files
committed
add agentapi test case
1 parent 2d72c03 commit 05e50d7

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

coderd/agentapi/manifest_test.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ func TestGetManifest(t *testing.T) {
156156
CollectedAt: someTime.Add(time.Hour),
157157
},
158158
}
159+
devcontainers = []database.WorkspaceAgentDevcontainer{
160+
{
161+
ID: uuid.New(),
162+
WorkspaceAgentID: agent.ID,
163+
WorkspaceFolder: "/cool/folder",
164+
},
165+
{
166+
ID: uuid.New(),
167+
WorkspaceAgentID: agent.ID,
168+
WorkspaceFolder: "/another/cool/folder",
169+
ConfigPath: "/another/cool/folder/.devcontainer/devcontainer.json",
170+
},
171+
}
159172
derpMapFn = func() *tailcfg.DERPMap {
160173
return &tailcfg.DERPMap{
161174
Regions: map[int]*tailcfg.DERPRegion{
@@ -267,6 +280,17 @@ func TestGetManifest(t *testing.T) {
267280
Timeout: durationpb.New(time.Duration(metadata[1].Timeout)),
268281
},
269282
}
283+
protoDevcontainers = []*agentproto.WorkspaceAgentDevcontainer{
284+
{
285+
Id: devcontainers[0].ID[:],
286+
WorkspaceFolder: devcontainers[0].WorkspaceFolder,
287+
},
288+
{
289+
Id: devcontainers[1].ID[:],
290+
WorkspaceFolder: devcontainers[1].WorkspaceFolder,
291+
ConfigPath: devcontainers[1].ConfigPath,
292+
},
293+
}
270294
)
271295

272296
t.Run("OK", func(t *testing.T) {
@@ -299,6 +323,7 @@ func TestGetManifest(t *testing.T) {
299323
WorkspaceAgentID: agent.ID,
300324
Keys: nil, // all
301325
}).Return(metadata, nil)
326+
mDB.EXPECT().GetWorkspaceAgentDevcontainersByWorkspaceAgentID(gomock.Any(), agent.ID).Return(devcontainers, nil)
302327
mDB.EXPECT().GetWorkspaceByID(gomock.Any(), workspace.ID).Return(workspace, nil)
303328
mDB.EXPECT().GetUserByID(gomock.Any(), workspace.OwnerID).Return(owner, nil)
304329

@@ -321,10 +346,11 @@ func TestGetManifest(t *testing.T) {
321346
// tailnet.DERPMapToProto() is extensively tested elsewhere, so it's
322347
// not necessary to manually recreate a big DERP map here like we
323348
// did for apps and metadata.
324-
DerpMap: tailnet.DERPMapToProto(derpMapFn()),
325-
Scripts: protoScripts,
326-
Apps: protoApps,
327-
Metadata: protoMetadata,
349+
DerpMap: tailnet.DERPMapToProto(derpMapFn()),
350+
Scripts: protoScripts,
351+
Apps: protoApps,
352+
Metadata: protoMetadata,
353+
Devcontainers: protoDevcontainers,
328354
}
329355

330356
// Log got and expected with spew.
@@ -364,6 +390,7 @@ func TestGetManifest(t *testing.T) {
364390
WorkspaceAgentID: agent.ID,
365391
Keys: nil, // all
366392
}).Return(metadata, nil)
393+
mDB.EXPECT().GetWorkspaceAgentDevcontainersByWorkspaceAgentID(gomock.Any(), agent.ID).Return(devcontainers, nil)
367394
mDB.EXPECT().GetWorkspaceByID(gomock.Any(), workspace.ID).Return(workspace, nil)
368395
mDB.EXPECT().GetUserByID(gomock.Any(), workspace.OwnerID).Return(owner, nil)
369396

@@ -386,10 +413,11 @@ func TestGetManifest(t *testing.T) {
386413
// tailnet.DERPMapToProto() is extensively tested elsewhere, so it's
387414
// not necessary to manually recreate a big DERP map here like we
388415
// did for apps and metadata.
389-
DerpMap: tailnet.DERPMapToProto(derpMapFn()),
390-
Scripts: protoScripts,
391-
Apps: protoApps,
392-
Metadata: protoMetadata,
416+
DerpMap: tailnet.DERPMapToProto(derpMapFn()),
417+
Scripts: protoScripts,
418+
Apps: protoApps,
419+
Metadata: protoMetadata,
420+
Devcontainers: protoDevcontainers,
393421
}
394422

395423
// Log got and expected with spew.

0 commit comments

Comments
 (0)