mirror of https://github.com/docker/cli.git
Merge pull request #26951 from AkihiroSuda/update-ut-cli-command-service
Fix cli/command/service/opts_test.go, and add some extra test cases
This commit is contained in:
commit
715d301f12
|
@ -235,10 +235,6 @@ func (m *MountOpt) Set(value string) error {
|
||||||
return fmt.Errorf("target is required")
|
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 {
|
if mount.Type == mounttypes.TypeBind && mount.VolumeOptions != nil {
|
||||||
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mounttypes.TypeBind)
|
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mounttypes.TypeBind)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func TestMountOptString(t *testing.T) {
|
||||||
assert.Equal(t, mount.String(), expected)
|
assert.Equal(t, mount.String(), expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetNoError(t *testing.T) {
|
func TestMountOptSetBindNoErrorBind(t *testing.T) {
|
||||||
for _, testcase := range []string{
|
for _, testcase := range []string{
|
||||||
// tests several aliases that should have same result.
|
// tests several aliases that should have same result.
|
||||||
"type=bind,target=/target,source=/source",
|
"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
|
// TestMountOptDefaultType ensures that a mount without the type defaults to a
|
||||||
// volume mount.
|
// volume mount.
|
||||||
func TestMountOptDefaultType(t *testing.T) {
|
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.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, true)
|
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{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
|
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, false)
|
assert.Equal(t, m.values[0].ReadOnly, false)
|
||||||
|
@ -147,7 +173,8 @@ func TestMountOptDefaultEnableReadOnly(t *testing.T) {
|
||||||
|
|
||||||
func TestMountOptVolumeNoCopy(t *testing.T) {
|
func TestMountOptVolumeNoCopy(t *testing.T) {
|
||||||
var m MountOpt
|
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{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))
|
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))
|
||||||
|
|
Loading…
Reference in New Issue