Skip to content

Commit

Permalink
Merge pull request #4423 from thaJeztah/24.0_backport_dont-ignore-vol…
Browse files Browse the repository at this point in the history
…ume-parse-err

[24.0 backport] cli/container: Don't ignore error when parsing volume spec
  • Loading branch information
thaJeztah authored Jul 17, 2023
2 parents 9edd9a1 + bfe2ff8 commit 809975d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
volumes := copts.volumes.GetMap()
// add any bind targets to the list of container volumes
for bind := range copts.volumes.GetMap() {
parsed, _ := loader.ParseVolume(bind)
parsed, err := loader.ParseVolume(bind)
if err != nil {
return nil, err
}

if parsed.Source != "" {
toBind := bind
Expand Down
5 changes: 5 additions & 0 deletions cli/compose/loader/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,8 @@ func TestParseVolumeInvalidSections(t *testing.T) {
_, err := ParseVolume("/foo::rw")
assert.ErrorContains(t, err, "invalid spec")
}

func TestParseVolumeWithEmptySource(t *testing.T) {
_, err := ParseVolume(":/vol")
assert.ErrorContains(t, err, "empty section between colons")
}
16 changes: 16 additions & 0 deletions e2e/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ func TestTrustedCreateFromBadTrustServer(t *testing.T) {
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",
})
}

0 comments on commit 809975d

Please sign in to comment.