From f9b457f152985ace959082f7712a8438c36bd01d Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 13 May 2015 16:45:44 -0700 Subject: [PATCH] fix image.Match Signed-off-by: Victor Vieux --- cluster/image.go | 3 ++- cluster/image_test.go | 24 ++++++++++++++++++++++++ test/integration/api/rmi.bats | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 cluster/image_test.go diff --git a/cluster/image.go b/cluster/image.go index 0552fa0e0c..7d395dbb5c 100644 --- a/cluster/image.go +++ b/cluster/image.go @@ -21,7 +21,8 @@ func (image *Image) Match(IDOrName string) bool { return true } for _, repoTag := range image.RepoTags { - if repoTag == IDOrName || (size > 2 && strings.HasPrefix(repoTag, IDOrName)) { + parts := strings.SplitN(repoTag, ":", 2) + if repoTag == IDOrName || parts[0] == IDOrName { return true } } diff --git a/cluster/image_test.go b/cluster/image_test.go new file mode 100644 index 0000000000..cab111e5c2 --- /dev/null +++ b/cluster/image_test.go @@ -0,0 +1,24 @@ +package cluster + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMatch(t *testing.T) { + img := Image{} + + img.Id = "378954456789" + img.RepoTags = []string{"name:latest"} + + assert.True(t, img.Match("378954456789")) + assert.True(t, img.Match("3789")) + assert.True(t, img.Match("378")) + assert.False(t, img.Match("37")) + + assert.True(t, img.Match("name:latest")) + assert.True(t, img.Match("name")) + assert.False(t, img.Match("nam")) + assert.False(t, img.Match("na")) +} diff --git a/test/integration/api/rmi.bats b/test/integration/api/rmi.bats index a6f95a03f1..4d97213123 100644 --- a/test/integration/api/rmi.bats +++ b/test/integration/api/rmi.bats @@ -47,3 +47,12 @@ function teardown() { [ "${#lines[@]}" -eq 0 ] done } + +@test "docker rmi prefix" { + start_docker_with_busybox 1 + swarm_manage + + run docker_swarm rmi bus + [ "$status" -ne 0 ] + [[ "${output}" == *"No such image"* ]] +}