github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/integration/daemon/daemon_test.go (about) 1 package daemon // import "github.com/docker/docker/integration/daemon" 2 3 import ( 4 "context" 5 "runtime" 6 "testing" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/api/types/mount" 10 "github.com/docker/docker/api/types/volume" 11 "github.com/docker/docker/integration/internal/container" 12 "github.com/docker/docker/testutil/daemon" 13 "gotest.tools/v3/assert" 14 "gotest.tools/v3/skip" 15 ) 16 17 func TestLiveRestore(t *testing.T) { 18 skip.If(t, runtime.GOOS == "windows", "cannot start multiple daemons on windows") 19 20 t.Run("volume references", testLiveRestoreVolumeReferences) 21 } 22 23 func testLiveRestoreVolumeReferences(t *testing.T) { 24 t.Parallel() 25 26 d := daemon.New(t) 27 d.StartWithBusybox(t, "--live-restore", "--iptables=false") 28 defer func() { 29 d.Stop(t) 30 d.Cleanup(t) 31 }() 32 33 c := d.NewClientT(t) 34 ctx := context.Background() 35 36 runTest := func(t *testing.T, policy string) { 37 t.Run(policy, func(t *testing.T) { 38 volName := "test-live-restore-volume-references-" + policy 39 _, err := c.VolumeCreate(ctx, volume.VolumeCreateBody{Name: volName}) 40 assert.NilError(t, err) 41 42 // Create a container that uses the volume 43 m := mount.Mount{ 44 Type: mount.TypeVolume, 45 Source: volName, 46 Target: "/foo", 47 } 48 cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"), container.WithRestartPolicy(policy)) 49 defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) 50 51 // Stop the daemon 52 d.Restart(t, "--live-restore", "--iptables=false") 53 54 // Try to remove the volume 55 err = c.VolumeRemove(ctx, volName, false) 56 assert.ErrorContains(t, err, "volume is in use") 57 58 _, err = c.VolumeInspect(ctx, volName) 59 assert.NilError(t, err) 60 }) 61 } 62 63 t.Run("restartPolicy", func(t *testing.T) { 64 runTest(t, "always") 65 runTest(t, "unless-stopped") 66 runTest(t, "on-failure") 67 runTest(t, "no") 68 }) 69 }