MCPcopy Index your code
hub / github.com/coder/coder / TestWithDevcontainersNameGeneration

Function TestWithDevcontainersNameGeneration

agent/agentcontainers/api_test.go:4286–4363  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4284}
4285
4286func TestWithDevcontainersNameGeneration(t *testing.T) {
4287 t.Parallel()
4288
4289 if runtime.GOOS == "windows" {
4290 t.Skip("Dev Container tests are not supported on Windows")
4291 }
4292
4293 devcontainers := []codersdk.WorkspaceAgentDevcontainer{
4294 {
4295 ID: uuid.New(),
4296 Name: "original-name",
4297 WorkspaceFolder: "/home/coder/foo/project",
4298 ConfigPath: "/home/coder/foo/project/.devcontainer/devcontainer.json",
4299 },
4300 {
4301 ID: uuid.New(),
4302 Name: "another-name",
4303 WorkspaceFolder: "/home/coder/bar/project",
4304 ConfigPath: "/home/coder/bar/project/.devcontainer/devcontainer.json",
4305 },
4306 }
4307
4308 scripts := []codersdk.WorkspaceAgentScript{
4309 {ID: devcontainers[0].ID, LogSourceID: uuid.New()},
4310 {ID: devcontainers[1].ID, LogSourceID: uuid.New()},
4311 }
4312
4313 logger := testutil.Logger(t)
4314
4315 // This should trigger the WithDevcontainers code path where names are generated
4316 api := agentcontainers.NewAPI(logger,
4317 agentcontainers.WithDevcontainers(devcontainers, scripts),
4318 agentcontainers.WithContainerCLI(&fakeContainerCLI{
4319 containers: codersdk.WorkspaceAgentListContainersResponse{
4320 Containers: []codersdk.WorkspaceAgentContainer{
4321 fakeContainer(t, func(c *codersdk.WorkspaceAgentContainer) {
4322 c.ID = "some-container-id-1"
4323 c.FriendlyName = "container-name-1"
4324 c.Labels[agentcontainers.DevcontainerLocalFolderLabel] = "/home/coder/baz/project"
4325 c.Labels[agentcontainers.DevcontainerConfigFileLabel] = "/home/coder/baz/project/.devcontainer/devcontainer.json"
4326 }),
4327 },
4328 },
4329 }),
4330 agentcontainers.WithDevcontainerCLI(&fakeDevcontainerCLI{}),
4331 agentcontainers.WithSubAgentClient(&fakeSubAgentClient{}),
4332 agentcontainers.WithWatcher(watcher.NewNoop()),
4333 )
4334 defer api.Close()
4335 api.Start()
4336
4337 r := chi.NewRouter()
4338 r.Mount("/", api.Routes())
4339
4340 ctx := context.Background()
4341
4342 err := api.RefreshContainers(ctx)
4343 require.NoError(t, err, "RefreshContainers should not error")

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartMethod · 0.95
RoutesMethod · 0.95
RefreshContainersMethod · 0.95
LoggerFunction · 0.92
NewAPIFunction · 0.92
WithDevcontainersFunction · 0.92
WithContainerCLIFunction · 0.92
WithDevcontainerCLIFunction · 0.92
WithSubAgentClientFunction · 0.92
WithWatcherFunction · 0.92
NewNoopFunction · 0.92

Tested by

no test coverage detected