mirror of https://github.com/docker/docs.git
use ParseRepositoryTag in image
Signed-off-by: ChangHai Yan <changhai.ych@alibaba-inc.com>
This commit is contained in:
parent
686f743856
commit
a59f3578ee
|
|
@ -123,3 +123,24 @@ func TestImagesFilterWithNameFilterWithTag(t *testing.T) {
|
|||
})
|
||||
assert.Equal(t, len(result), 2)
|
||||
}
|
||||
|
||||
func TestParseRepositoryTag(t *testing.T) {
|
||||
|
||||
repo, tag := parseRepositoryTag("localhost.localdomain:5000/samalba/hipache:latest")
|
||||
if tag != "latest" {
|
||||
t.Errorf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
repo, tag = parseRepositoryTag("localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb")
|
||||
if tag != "sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb" {
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
repo, tag = parseRepositoryTag("localhost:5000/foo/bar")
|
||||
if tag != "" {
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
repo, tag = parseRepositoryTag("localhost:5000/foo/bar:latest")
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
if tag != "latest" {
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func (f *AffinityFilter) Filter(config *cluster.ContainerConfig, nodes []*node.N
|
|||
images = append(images, image.Id)
|
||||
images = append(images, image.RepoTags...)
|
||||
for _, tag := range image.RepoTags {
|
||||
repo, _ := parseRepositoryTag(tag)
|
||||
repo, _ := cluster.ParseRepositoryTag(tag)
|
||||
images = append(images, repo)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
package filter
|
||||
|
||||
import "strings"
|
||||
|
||||
// Get a repos name and returns the right reposName + tag|digest
|
||||
// The tag can be confusing because of a port in a repository name.
|
||||
// Ex: localhost.localdomain:5000/samalba/hipache:latest
|
||||
// Digest ex: localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb
|
||||
func parseRepositoryTag(repos string) (string, string) {
|
||||
n := strings.Index(repos, "@")
|
||||
if n >= 0 {
|
||||
parts := strings.Split(repos, "@")
|
||||
return parts[0], parts[1]
|
||||
}
|
||||
n = strings.LastIndex(repos, ":")
|
||||
if n < 0 {
|
||||
return repos, ""
|
||||
}
|
||||
if tag := repos[n+1:]; !strings.Contains(tag, "/") {
|
||||
return repos[:n], tag
|
||||
}
|
||||
return repos, ""
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package filter
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseRepositoryTag(t *testing.T) {
|
||||
|
||||
repo, tag := parseRepositoryTag("localhost.localdomain:5000/samalba/hipache:latest")
|
||||
if tag != "latest" {
|
||||
t.Errorf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
repo, tag = parseRepositoryTag("localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb")
|
||||
if tag != "sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb" {
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
repo, tag = parseRepositoryTag("localhost:5000/foo/bar")
|
||||
if tag != "" {
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
repo, tag = parseRepositoryTag("localhost:5000/foo/bar:latest")
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
if tag != "latest" {
|
||||
t.Logf("repo=%s tag=%s", repo, tag)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue