From 2126d8160d69e2d577cb12f8ad6a6602baa8e717 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 27 Sep 2016 15:27:02 +0000 Subject: [PATCH] Fix cli/command/service/opts_test.go, and add some extra test cases `m.Set("type=volume,target=/foo,volume-nocopy")` is valid even though it lacks "source" Signed-off-by: Akihiro Suda --- command/service/opts.go | 4 ---- command/service/opts_test.go | 31 +++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/command/service/opts.go b/command/service/opts.go index 7236980e80..1e966f90c6 100644 --- a/command/service/opts.go +++ b/command/service/opts.go @@ -235,10 +235,6 @@ func (m *MountOpt) Set(value string) error { return fmt.Errorf("target is required") } - if mount.VolumeOptions != nil && mount.Source == "" { - return fmt.Errorf("source is required when specifying volume-* options") - } - if mount.Type == mounttypes.TypeBind && mount.VolumeOptions != nil { return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mounttypes.TypeBind) } diff --git a/command/service/opts_test.go b/command/service/opts_test.go index 30e261b8de..8ef3cacb45 100644 --- a/command/service/opts_test.go +++ b/command/service/opts_test.go @@ -76,7 +76,7 @@ func TestMountOptString(t *testing.T) { assert.Equal(t, mount.String(), expected) } -func TestMountOptSetNoError(t *testing.T) { +func TestMountOptSetBindNoErrorBind(t *testing.T) { for _, testcase := range []string{ // tests several aliases that should have same result. "type=bind,target=/target,source=/source", @@ -98,6 +98,28 @@ func TestMountOptSetNoError(t *testing.T) { } } +func TestMountOptSetVolumeNoError(t *testing.T) { + for _, testcase := range []string{ + // tests several aliases that should have same result. + "type=volume,target=/target,source=/source", + "type=volume,src=/source,dst=/target", + "type=volume,source=/source,dst=/target", + "type=volume,src=/source,target=/target", + } { + var mount MountOpt + + assert.NilError(t, mount.Set(testcase)) + + mounts := mount.Value() + assert.Equal(t, len(mounts), 1) + assert.Equal(t, mounts[0], mounttypes.Mount{ + Type: mounttypes.TypeVolume, + Source: "/source", + Target: "/target", + }) + } +} + // TestMountOptDefaultType ensures that a mount without the type defaults to a // volume mount. func TestMountOptDefaultType(t *testing.T) { @@ -140,6 +162,10 @@ func TestMountOptDefaultEnableReadOnly(t *testing.T) { assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1")) assert.Equal(t, m.values[0].ReadOnly, true) + m = MountOpt{} + assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true")) + assert.Equal(t, m.values[0].ReadOnly, true) + m = MountOpt{} assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0")) assert.Equal(t, m.values[0].ReadOnly, false) @@ -147,7 +173,8 @@ func TestMountOptDefaultEnableReadOnly(t *testing.T) { func TestMountOptVolumeNoCopy(t *testing.T) { var m MountOpt - assert.Error(t, m.Set("type=volume,target=/foo,volume-nocopy"), "source is required") + assert.NilError(t, m.Set("type=volume,target=/foo,volume-nocopy")) + assert.Equal(t, m.values[0].Source, "") m = MountOpt{} assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))