Procházet zdrojové kódy

Merge pull request #26951 from AkihiroSuda/update-ut-cli-command-service

Fix cli/command/service/opts_test.go, and add some extra test cases
Brian Goff před 8 roky
rodič
revize
9a2f01ef13
2 změnil soubory, kde provedl 29 přidání a 6 odebrání
  1. 0 4
      cli/command/service/opts.go
  2. 29 2
      cli/command/service/opts_test.go

+ 0 - 4
cli/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)
 	}

+ 29 - 2
cli/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"))