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

Function removeDevcontainerByID

agent/agentcontainers/devcontainercli_test.go:644–669  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

642// removeDevcontainerByID safely cleans up a test container by ID, verifying
643// it has our test label before removal to prevent accidental deletion.
644func 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
671func TestDevcontainerFeatures_OptionsAsEnvs(t *testing.T) {
672 t.Parallel()

Callers 1

Calls 4

AsMethod · 0.80
HelperMethod · 0.65
LogfMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected