`m.Set("type=volume,target=/foo,volume-nocopy")` is valid even though it lacks "source"
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
| ... | ... |
@@ -235,10 +235,6 @@ func (m *MountOpt) Set(value string) error {
|
| 235 | 235 |
return fmt.Errorf("target is required")
|
| 236 | 236 |
} |
| 237 | 237 |
|
| 238 |
- if mount.VolumeOptions != nil && mount.Source == "" {
|
|
| 239 |
- return fmt.Errorf("source is required when specifying volume-* options")
|
|
| 240 |
- } |
|
| 241 |
- |
|
| 242 | 238 |
if mount.Type == mounttypes.TypeBind && mount.VolumeOptions != nil {
|
| 243 | 239 |
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mounttypes.TypeBind)
|
| 244 | 240 |
} |
| ... | ... |
@@ -76,7 +76,7 @@ func TestMountOptString(t *testing.T) {
|
| 76 | 76 |
assert.Equal(t, mount.String(), expected) |
| 77 | 77 |
} |
| 78 | 78 |
|
| 79 |
-func TestMountOptSetNoError(t *testing.T) {
|
|
| 79 |
+func TestMountOptSetBindNoErrorBind(t *testing.T) {
|
|
| 80 | 80 |
for _, testcase := range []string{
|
| 81 | 81 |
// tests several aliases that should have same result. |
| 82 | 82 |
"type=bind,target=/target,source=/source", |
| ... | ... |
@@ -98,6 +98,28 @@ func TestMountOptSetNoError(t *testing.T) {
|
| 98 | 98 |
} |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 |
+func TestMountOptSetVolumeNoError(t *testing.T) {
|
|
| 102 |
+ for _, testcase := range []string{
|
|
| 103 |
+ // tests several aliases that should have same result. |
|
| 104 |
+ "type=volume,target=/target,source=/source", |
|
| 105 |
+ "type=volume,src=/source,dst=/target", |
|
| 106 |
+ "type=volume,source=/source,dst=/target", |
|
| 107 |
+ "type=volume,src=/source,target=/target", |
|
| 108 |
+ } {
|
|
| 109 |
+ var mount MountOpt |
|
| 110 |
+ |
|
| 111 |
+ assert.NilError(t, mount.Set(testcase)) |
|
| 112 |
+ |
|
| 113 |
+ mounts := mount.Value() |
|
| 114 |
+ assert.Equal(t, len(mounts), 1) |
|
| 115 |
+ assert.Equal(t, mounts[0], mounttypes.Mount{
|
|
| 116 |
+ Type: mounttypes.TypeVolume, |
|
| 117 |
+ Source: "/source", |
|
| 118 |
+ Target: "/target", |
|
| 119 |
+ }) |
|
| 120 |
+ } |
|
| 121 |
+} |
|
| 122 |
+ |
|
| 101 | 123 |
// TestMountOptDefaultType ensures that a mount without the type defaults to a |
| 102 | 124 |
// volume mount. |
| 103 | 125 |
func TestMountOptDefaultType(t *testing.T) {
|
| ... | ... |
@@ -141,13 +163,18 @@ func TestMountOptDefaultEnableReadOnly(t *testing.T) {
|
| 141 | 141 |
assert.Equal(t, m.values[0].ReadOnly, true) |
| 142 | 142 |
|
| 143 | 143 |
m = MountOpt{}
|
| 144 |
+ assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true"))
|
|
| 145 |
+ assert.Equal(t, m.values[0].ReadOnly, true) |
|
| 146 |
+ |
|
| 147 |
+ m = MountOpt{}
|
|
| 144 | 148 |
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
|
| 145 | 149 |
assert.Equal(t, m.values[0].ReadOnly, false) |
| 146 | 150 |
} |
| 147 | 151 |
|
| 148 | 152 |
func TestMountOptVolumeNoCopy(t *testing.T) {
|
| 149 | 153 |
var m MountOpt |
| 150 |
- assert.Error(t, m.Set("type=volume,target=/foo,volume-nocopy"), "source is required")
|
|
| 154 |
+ assert.NilError(t, m.Set("type=volume,target=/foo,volume-nocopy"))
|
|
| 155 |
+ assert.Equal(t, m.values[0].Source, "") |
|
| 151 | 156 |
|
| 152 | 157 |
m = MountOpt{}
|
| 153 | 158 |
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))
|