mirror of https://github.com/docker/cli.git
cli/container: Don't ignore error when parsing volume spec
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit fe7afb700f
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
380eb72940
commit
bfe2ff8208
|
@ -354,7 +354,10 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
||||||
volumes := copts.volumes.GetMap()
|
volumes := copts.volumes.GetMap()
|
||||||
// add any bind targets to the list of container volumes
|
// add any bind targets to the list of container volumes
|
||||||
for bind := range copts.volumes.GetMap() {
|
for bind := range copts.volumes.GetMap() {
|
||||||
parsed, _ := loader.ParseVolume(bind)
|
parsed, err := loader.ParseVolume(bind)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if parsed.Source != "" {
|
if parsed.Source != "" {
|
||||||
toBind := bind
|
toBind := bind
|
||||||
|
|
|
@ -223,3 +223,8 @@ func TestParseVolumeInvalidSections(t *testing.T) {
|
||||||
_, err := ParseVolume("/foo::rw")
|
_, err := ParseVolume("/foo::rw")
|
||||||
assert.ErrorContains(t, err, "invalid spec")
|
assert.ErrorContains(t, err, "invalid spec")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseVolumeWithEmptySource(t *testing.T) {
|
||||||
|
_, err := ParseVolume(":/vol")
|
||||||
|
assert.ErrorContains(t, err, "empty section between colons")
|
||||||
|
}
|
||||||
|
|
|
@ -101,3 +101,19 @@ func TestTrustedCreateFromBadTrustServer(t *testing.T) {
|
||||||
Err: "could not rotate trust to a new trusted root",
|
Err: "could not rotate trust to a new trusted root",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateWithEmptySourceVolume(t *testing.T) {
|
||||||
|
icmd.RunCmd(icmd.Command("docker", "create", "-v", ":/volume", fixtures.AlpineImage)).
|
||||||
|
Assert(t, icmd.Expected{
|
||||||
|
ExitCode: 125,
|
||||||
|
Err: "empty section between colons",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateWithEmptyVolumeSpec(t *testing.T) {
|
||||||
|
icmd.RunCmd(icmd.Command("docker", "create", "-v", "", fixtures.AlpineImage)).
|
||||||
|
Assert(t, icmd.Expected{
|
||||||
|
ExitCode: 125,
|
||||||
|
Err: "invalid empty volume spec",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue