MCPcopy Index your code
hub / github.com/coder/envbox / TestDocker

Function TestDocker

integration/docker_test.go:22–684  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestDocker(t *testing.T) {
23 t.Parallel()
24 if val, ok := os.LookupEnv("CODER_TEST_INTEGRATION"); !ok || val != "1" {
25 t.Skip("integration tests are skipped unless CODER_TEST_INTEGRATION=1")
26 }
27
28 // Dockerd just tests that dockerd can spin up and function correctly.
29 t.Run("Dockerd", func(t *testing.T) {
30 t.Parallel()
31
32 pool, err := dockertest.NewPool("")
33 require.NoError(t, err)
34
35 var (
36 tmpdir = integrationtest.TmpDir(t)
37 binds = integrationtest.DefaultBinds(t, tmpdir)
38 )
39
40 runEnvbox := func() *dockertest.Resource {
41 // Run the envbox container.
42 resource := integrationtest.RunEnvbox(t, pool, &integrationtest.CreateDockerCVMConfig{
43 Image: integrationtest.DockerdImage,
44 Username: "root",
45 OuterMounts: binds,
46 })
47
48 // Wait for the inner container's docker daemon.
49 integrationtest.WaitForCVMDocker(t, pool, resource, time.Minute)
50
51 // Assert that we can run docker in the inner container.
52 _, err = integrationtest.ExecInnerContainer(t, pool, integrationtest.ExecConfig{
53 ContainerID: resource.Container.ID,
54 Cmd: []string{"docker", "run", integrationtest.HelloWorldImage},
55 })
56
57 require.NoError(t, err)
58 return resource
59 }
60
61 // Run envbox initially, this tests the initial creation of a workspace.
62 resource := runEnvbox()
63
64 t.Logf("envbox %q started successfully, recreating...", resource.Container.ID)
65
66 // Destroy the container, we're going to recreate it to ensure that when volumes are reused
67 // IDs are still mapped correctly.
68 err = resource.Close()
69 require.NoError(t, err)
70
71 // Run envbox again to test that when we restart a workspace things still
72 // work correctly.
73 _ = runEnvbox()
74 })
75
76 // EnvboxArgs validates that arguments passed to envbox function correctly.
77 // Most cases should be covered with unit tests, the intent with this is to
78 // test cases that do not garner a high degree of confidence from mocking
79 // (such as creating devices e.g. FUSE, TUN).

Callers

nothing calls this directly

Calls 15

TmpDirFunction · 0.92
DefaultBindsFunction · 0.92
RunEnvboxFunction · 0.92
WaitForCVMDockerFunction · 0.92
ExecInnerContainerFunction · 0.92
BindMountFunction · 0.92
ExecEnvboxFunction · 0.92
DockerBridgeIPFunction · 0.92
GenerateTLSCertificateFunction · 0.92
FakeBuildLogRecorderFunction · 0.92
MkdirAllFunction · 0.92
WriteCertificateFunction · 0.92

Tested by

no test coverage detected