diff --git a/pkg/api/volume.go b/pkg/api/volume.go index 250ce363..67caf458 100644 --- a/pkg/api/volume.go +++ b/pkg/api/volume.go @@ -83,6 +83,9 @@ func (v *VolumeSpec) SetDefaults() VolumeSpec { if spec.VolumeOptions.Name == "" { spec.VolumeOptions.Name = spec.Name } + if spec.VolumeOptions.Driver != nil && spec.VolumeOptions.Driver.Name == "" { + spec.VolumeOptions.Driver.Name = VolumeDriverLocal + } } // TODO: set explicit default values for Propagation and Recursive for bind mounts? diff --git a/pkg/api/volume_test.go b/pkg/api/volume_test.go new file mode 100644 index 00000000..0e41befa --- /dev/null +++ b/pkg/api/volume_test.go @@ -0,0 +1,68 @@ +package api + +import ( + "testing" + + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/api/types/volume" + "github.com/stretchr/testify/assert" +) + +func TestVolumeSpec_MatchesDockerVolume(t *testing.T) { + tests := []struct { + name string + spec VolumeSpec + vol volume.Volume + expected bool + }{ + { + name: "match with explicit local driver", + spec: VolumeSpec{ + Type: VolumeTypeVolume, + VolumeOptions: &VolumeOptions{ + Driver: &mount.Driver{ + Name: "local", + Options: map[string]string{ + "foo": "bar", + }, + }, + }, + }, + vol: volume.Volume{ + Driver: "local", + Options: map[string]string{ + "foo": "bar", + }, + }, + expected: true, + }, + { + name: "match with empty driver name in spec (implicit local)", + spec: VolumeSpec{ + Type: VolumeTypeVolume, + VolumeOptions: &VolumeOptions{ + Driver: &mount.Driver{ + Name: "", // Implicitly local + Options: map[string]string{ + "foo": "bar", + }, + }, + }, + }, + vol: volume.Volume{ + Driver: "local", + Options: map[string]string{ + "foo": "bar", + }, + }, + expected: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + matches := tt.spec.MatchesDockerVolume(tt.vol) + assert.Equal(t, tt.expected, matches) + }) + } +}