|
@@ -8,51 +8,48 @@ import (
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
|
|
)
|
|
|
|
|
|
-func TestIsReadOnly(t *testing.T) {
|
|
|
- assert.Equal(t, isReadOnly([]string{"foo", "bar", "ro"}), true)
|
|
|
- assert.Equal(t, isReadOnly([]string{"ro"}), true)
|
|
|
- assert.Equal(t, isReadOnly([]string{}), false)
|
|
|
- assert.Equal(t, isReadOnly([]string{"foo", "rw"}), false)
|
|
|
- assert.Equal(t, isReadOnly([]string{"foo"}), false)
|
|
|
-}
|
|
|
-
|
|
|
-func TestIsNoCopy(t *testing.T) {
|
|
|
- assert.Equal(t, isNoCopy([]string{"foo", "bar", "nocopy"}), true)
|
|
|
- assert.Equal(t, isNoCopy([]string{"nocopy"}), true)
|
|
|
- assert.Equal(t, isNoCopy([]string{}), false)
|
|
|
- assert.Equal(t, isNoCopy([]string{"foo", "rw"}), false)
|
|
|
-}
|
|
|
-
|
|
|
-func TestGetBindOptions(t *testing.T) {
|
|
|
- opts := getBindOptions([]string{"slave"})
|
|
|
- expected := mount.BindOptions{Propagation: mount.PropagationSlave}
|
|
|
- assert.Equal(t, *opts, expected)
|
|
|
-}
|
|
|
-
|
|
|
-func TestGetBindOptionsNone(t *testing.T) {
|
|
|
- opts := getBindOptions([]string{"ro"})
|
|
|
- assert.Equal(t, opts, (*mount.BindOptions)(nil))
|
|
|
-}
|
|
|
-
|
|
|
func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
|
|
- stackVolumes := volumes{}
|
|
|
- namespace := NewNamespace("foo")
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "volume",
|
|
|
+ Target: "/foo/bar",
|
|
|
+ }
|
|
|
expected := mount.Mount{
|
|
|
Type: mount.TypeVolume,
|
|
|
Target: "/foo/bar",
|
|
|
}
|
|
|
- mount, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
|
|
|
+ mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
|
|
|
assert.NilError(t, err)
|
|
|
assert.DeepEqual(t, mount, expected)
|
|
|
}
|
|
|
|
|
|
-func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
|
|
|
+func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) {
|
|
|
namespace := NewNamespace("foo")
|
|
|
- invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
|
|
|
- for _, vol := range invalids {
|
|
|
- _, err := convertVolumeToMount(vol, volumes{}, namespace)
|
|
|
- assert.Error(t, err, "invalid volume: "+vol)
|
|
|
+
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "volume",
|
|
|
+ Source: "foo",
|
|
|
+ Target: "/target",
|
|
|
+ Bind: &composetypes.ServiceVolumeBind{
|
|
|
+ Propagation: "slave",
|
|
|
+ },
|
|
|
}
|
|
|
+ _, err := convertVolumeToMount(config, volumes{}, namespace)
|
|
|
+ assert.Error(t, err, "bind options are incompatible")
|
|
|
+}
|
|
|
+
|
|
|
+func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) {
|
|
|
+ namespace := NewNamespace("foo")
|
|
|
+
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "bind",
|
|
|
+ Source: "/foo",
|
|
|
+ Target: "/target",
|
|
|
+ Volume: &composetypes.ServiceVolumeVolume{
|
|
|
+ NoCopy: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _, err := convertVolumeToMount(config, volumes{}, namespace)
|
|
|
+ assert.Error(t, err, "volume options are incompatible")
|
|
|
}
|
|
|
|
|
|
func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
|
@@ -84,9 +81,19 @@ func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
|
|
"opt": "value",
|
|
|
},
|
|
|
},
|
|
|
+ NoCopy: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "volume",
|
|
|
+ Source: "normal",
|
|
|
+ Target: "/foo",
|
|
|
+ ReadOnly: true,
|
|
|
+ Volume: &composetypes.ServiceVolumeVolume{
|
|
|
+ NoCopy: true,
|
|
|
},
|
|
|
}
|
|
|
- mount, err := convertVolumeToMount("normal:/foo:ro", stackVolumes, namespace)
|
|
|
+ mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
|
|
assert.NilError(t, err)
|
|
|
assert.DeepEqual(t, mount, expected)
|
|
|
}
|
|
@@ -109,7 +116,12 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
|
|
|
NoCopy: false,
|
|
|
},
|
|
|
}
|
|
|
- mount, err := convertVolumeToMount("outside:/foo", stackVolumes, namespace)
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "volume",
|
|
|
+ Source: "outside",
|
|
|
+ Target: "/foo",
|
|
|
+ }
|
|
|
+ mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
|
|
assert.NilError(t, err)
|
|
|
assert.DeepEqual(t, mount, expected)
|
|
|
}
|
|
@@ -132,7 +144,15 @@ func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
|
|
|
NoCopy: true,
|
|
|
},
|
|
|
}
|
|
|
- mount, err := convertVolumeToMount("outside:/foo:nocopy", stackVolumes, namespace)
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "volume",
|
|
|
+ Source: "outside",
|
|
|
+ Target: "/foo",
|
|
|
+ Volume: &composetypes.ServiceVolumeVolume{
|
|
|
+ NoCopy: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
|
|
assert.NilError(t, err)
|
|
|
assert.DeepEqual(t, mount, expected)
|
|
|
}
|
|
@@ -147,13 +167,26 @@ func TestConvertVolumeToMountBind(t *testing.T) {
|
|
|
ReadOnly: true,
|
|
|
BindOptions: &mount.BindOptions{Propagation: mount.PropagationShared},
|
|
|
}
|
|
|
- mount, err := convertVolumeToMount("/bar:/foo:ro,shared", stackVolumes, namespace)
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "bind",
|
|
|
+ Source: "/bar",
|
|
|
+ Target: "/foo",
|
|
|
+ ReadOnly: true,
|
|
|
+ Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"},
|
|
|
+ }
|
|
|
+ mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
|
|
assert.NilError(t, err)
|
|
|
assert.DeepEqual(t, mount, expected)
|
|
|
}
|
|
|
|
|
|
func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
|
|
|
namespace := NewNamespace("foo")
|
|
|
- _, err := convertVolumeToMount("unknown:/foo:ro", volumes{}, namespace)
|
|
|
+ config := composetypes.ServiceVolumeConfig{
|
|
|
+ Type: "volume",
|
|
|
+ Source: "unknown",
|
|
|
+ Target: "/foo",
|
|
|
+ ReadOnly: true,
|
|
|
+ }
|
|
|
+ _, err := convertVolumeToMount(config, volumes{}, namespace)
|
|
|
assert.Error(t, err, "undefined volume: unknown")
|
|
|
}
|