removeDevcontainerByID safely cleans up a test container by ID, verifying it has our test label before removal to prevent accidental deletion.
(t *testing.T, pool *dockertest.Pool, id string)
| 642 | // removeDevcontainerByID safely cleans up a test container by ID, verifying |
| 643 | // it has our test label before removal to prevent accidental deletion. |
| 644 | func removeDevcontainerByID(t *testing.T, pool *dockertest.Pool, id string) { |
| 645 | t.Helper() |
| 646 | |
| 647 | errNoSuchContainer := &docker.NoSuchContainer{} |
| 648 | |
| 649 | // Check if the container has the expected label. |
| 650 | container, err := pool.Client.InspectContainer(id) |
| 651 | if err != nil { |
| 652 | if errors.As(err, &errNoSuchContainer) { |
| 653 | t.Logf("Container %s not found, skipping removal", id) |
| 654 | return |
| 655 | } |
| 656 | require.NoError(t, err, "inspect container") |
| 657 | } |
| 658 | require.Equal(t, "devcontainercli", container.Config.Labels["com.coder.test"], "sanity check failed: container should have the test label") |
| 659 | |
| 660 | t.Logf("Removing container with ID: %s", id) |
| 661 | err = pool.Client.RemoveContainer(docker.RemoveContainerOptions{ |
| 662 | ID: container.ID, |
| 663 | Force: true, |
| 664 | RemoveVolumes: true, |
| 665 | }) |
| 666 | if err != nil && !errors.As(err, &errNoSuchContainer) { |
| 667 | assert.NoError(t, err, "remove container failed") |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | func TestDevcontainerFeatures_OptionsAsEnvs(t *testing.T) { |
| 672 | t.Parallel() |
no test coverage detected