зеркало из https://github.com/microsoft/docker.git
Sort images by tag name when the creation date is the same.
This establishes a strict alphabetical order for tags with the same creation date.
This commit is contained in:
Родитель
cd6aeaf979
Коммит
e6affb1b1a
|
@ -242,7 +242,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
|
|||
}
|
||||
}
|
||||
|
||||
sortImagesByCreation(outs)
|
||||
sortImagesByCreationAndTag(outs)
|
||||
return outs, nil
|
||||
}
|
||||
|
||||
|
|
10
sorter.go
10
sorter.go
|
@ -22,15 +22,15 @@ func (s *imageSorter) Less(i, j int) bool {
|
|||
return s.by(&s.images[i], &s.images[j])
|
||||
}
|
||||
|
||||
// Sort []ApiImages by most recent creation date.
|
||||
func sortImagesByCreation(images []APIImages) {
|
||||
creation := func(i1, i2 *APIImages) bool {
|
||||
return i1.Created > i2.Created
|
||||
// Sort []ApiImages by most recent creation date and tag name.
|
||||
func sortImagesByCreationAndTag(images []APIImages) {
|
||||
creationAndTag := func(i1, i2 *APIImages) bool {
|
||||
return i1.Created > i2.Created || (i1.Created == i2.Created && i2.Tag > i1.Tag)
|
||||
}
|
||||
|
||||
sorter := &imageSorter{
|
||||
images: images,
|
||||
by: creation}
|
||||
by: creationAndTag}
|
||||
|
||||
sort.Sort(sorter)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestServerListOrderedImages(t *testing.T) {
|
||||
func TestServerListOrderedImagesByCreationDate(t *testing.T) {
|
||||
runtime := mkRuntime(t)
|
||||
defer nuke(runtime)
|
||||
|
||||
|
@ -28,3 +28,30 @@ func TestServerListOrderedImages(t *testing.T) {
|
|||
t.Error("Expected []APIImges to be ordered by most recent creation date.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerListOrderedImagesByCreationDateAndTag(t *testing.T) {
|
||||
runtime := mkRuntime(t)
|
||||
defer nuke(runtime)
|
||||
|
||||
archive, err := fakeTar()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
image, err := runtime.graph.Create(archive, nil, "Testing", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
srv := &Server{runtime: runtime}
|
||||
srv.ContainerTag(image.ID, "repo", "foo", false)
|
||||
srv.ContainerTag(image.ID, "repo", "bar", false)
|
||||
|
||||
images, err := srv.Images(true, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if images[0].Created != images[1].Created || images[0].Tag >= images[1].Tag {
|
||||
t.Error("Expected []APIImges to be ordered by most recent creation date and tag name.")
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче