summaryrefslogtreecommitdiff
path: root/integration/daemon/daemon_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'integration/daemon/daemon_test.go')
-rw-r--r--integration/daemon/daemon_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/integration/daemon/daemon_test.go b/integration/daemon/daemon_test.go
index 72ffdd1dbf..42e4155269 100644
--- a/integration/daemon/daemon_test.go
+++ b/integration/daemon/daemon_test.go
@@ -14,7 +14,10 @@ import (
"testing"
"github.com/docker/docker/api/types"
+ "github.com/docker/docker/api/types/mount"
+ "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/daemon/config"
+ "github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil/daemon"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@@ -378,3 +381,57 @@ func TestDaemonProxy(t *testing.T) {
assert.Assert(t, !strings.Contains(string(logs), userPass), "logs should not contain the non-sanitized proxy URL: %s", string(logs))
})
}
+
+func TestLiveRestore(t *testing.T) {
+ skip.If(t, runtime.GOOS == "windows", "cannot start multiple daemons on windows")
+
+ t.Run("volume references", testLiveRestoreVolumeReferences)
+}
+
+func testLiveRestoreVolumeReferences(t *testing.T) {
+ t.Parallel()
+
+ d := daemon.New(t)
+ d.StartWithBusybox(t, "--live-restore", "--iptables=false")
+ defer func() {
+ d.Stop(t)
+ d.Cleanup(t)
+ }()
+
+ c := d.NewClientT(t)
+ ctx := context.Background()
+
+ runTest := func(t *testing.T, policy string) {
+ t.Run(policy, func(t *testing.T) {
+ volName := "test-live-restore-volume-references-" + policy
+ _, err := c.VolumeCreate(ctx, volume.CreateOptions{Name: volName})
+ assert.NilError(t, err)
+
+ // Create a container that uses the volume
+ m := mount.Mount{
+ Type: mount.TypeVolume,
+ Source: volName,
+ Target: "/foo",
+ }
+ cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"), container.WithRestartPolicy(policy))
+ defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
+
+ // Stop the daemon
+ d.Restart(t, "--live-restore", "--iptables=false")
+
+ // Try to remove the volume
+ err = c.VolumeRemove(ctx, volName, false)
+ assert.ErrorContains(t, err, "volume is in use")
+
+ _, err = c.VolumeInspect(ctx, volName)
+ assert.NilError(t, err)
+ })
+ }
+
+ t.Run("restartPolicy", func(t *testing.T) {
+ runTest(t, "always")
+ runTest(t, "unless-stopped")
+ runTest(t, "on-failure")
+ runTest(t, "no")
+ })
+}