(t *testing.T)
| 4284 | } |
| 4285 | |
| 4286 | func 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") |
nothing calls this directly
no test coverage detected