(t *testing.T)
| 1357 | } |
| 1358 | |
| 1359 | func TestWorkspaceAgentContainers(t *testing.T) { |
| 1360 | t.Parallel() |
| 1361 | |
| 1362 | // This test will not normally run in CI, but is kept here as a semi-manual |
| 1363 | // test for local development. Run it as follows: |
| 1364 | // CODER_TEST_USE_DOCKER=1 go test -run TestWorkspaceAgentContainers/Docker ./coderd |
| 1365 | t.Run("Docker", func(t *testing.T) { |
| 1366 | t.Parallel() |
| 1367 | if ctud, ok := os.LookupEnv("CODER_TEST_USE_DOCKER"); !ok || ctud != "1" { |
| 1368 | t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test") |
| 1369 | } |
| 1370 | |
| 1371 | pool, err := dockertest.NewPool("") |
| 1372 | require.NoError(t, err, "Could not connect to docker") |
| 1373 | testLabels := map[string]string{ |
| 1374 | "com.coder.test": uuid.New().String(), |
| 1375 | "com.coder.empty": "", |
| 1376 | } |
| 1377 | ct, err := pool.RunWithOptions(&dockertest.RunOptions{ |
| 1378 | Repository: "busybox", |
| 1379 | Tag: "latest", |
| 1380 | Cmd: []string{"sleep", "infinity"}, |
| 1381 | Labels: testLabels, |
| 1382 | }, func(config *docker.HostConfig) { |
| 1383 | config.AutoRemove = true |
| 1384 | config.RestartPolicy = docker.RestartPolicy{Name: "no"} |
| 1385 | }) |
| 1386 | require.NoError(t, err, "Could not start test docker container") |
| 1387 | t.Cleanup(func() { |
| 1388 | assert.NoError(t, pool.Purge(ct), "Could not purge resource %q", ct.Container.Name) |
| 1389 | }) |
| 1390 | |
| 1391 | // Start another container which we will expect to ignore. |
| 1392 | ct2, err := pool.RunWithOptions(&dockertest.RunOptions{ |
| 1393 | Repository: "busybox", |
| 1394 | Tag: "latest", |
| 1395 | Cmd: []string{"sleep", "infinity"}, |
| 1396 | Labels: map[string]string{ |
| 1397 | "com.coder.test": "ignoreme", |
| 1398 | "com.coder.empty": "", |
| 1399 | }, |
| 1400 | }, func(config *docker.HostConfig) { |
| 1401 | config.AutoRemove = true |
| 1402 | config.RestartPolicy = docker.RestartPolicy{Name: "no"} |
| 1403 | }) |
| 1404 | require.NoError(t, err, "Could not start second test docker container") |
| 1405 | t.Cleanup(func() { |
| 1406 | assert.NoError(t, pool.Purge(ct2), "Could not purge resource %q", ct2.Container.Name) |
| 1407 | }) |
| 1408 | |
| 1409 | client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{}) |
| 1410 | |
| 1411 | user := coderdtest.CreateFirstUser(t, client) |
| 1412 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 1413 | OrganizationID: user.OrganizationID, |
| 1414 | OwnerID: user.UserID, |
| 1415 | }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { |
| 1416 | return agents |
nothing calls this directly
no test coverage detected