Merge pull request #783 from vieux/fix_image_match

fix image.Match to take only repo or repo:tag
This commit is contained in:
Andrea Luzzardi 2015-05-13 19:05:30 -07:00
commit ece52698d6
3 changed files with 35 additions and 1 deletions

View File

@ -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
}
}

24
cluster/image_test.go Normal file
View File

@ -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"))
}

View File

@ -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"* ]]
}