mirror of https://github.com/docker/docs.git
Merge pull request #783 from vieux/fix_image_match
fix image.Match to take only repo or repo:tag
This commit is contained in:
commit
ece52698d6
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
|
@ -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"* ]]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue