mirror of https://github.com/docker/docs.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:
parent
cd6aeaf979
commit
e6affb1b1a
|
@ -242,7 +242,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortImagesByCreation(outs)
|
sortImagesByCreationAndTag(outs)
|
||||||
return outs, nil
|
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])
|
return s.by(&s.images[i], &s.images[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort []ApiImages by most recent creation date.
|
// Sort []ApiImages by most recent creation date and tag name.
|
||||||
func sortImagesByCreation(images []APIImages) {
|
func sortImagesByCreationAndTag(images []APIImages) {
|
||||||
creation := func(i1, i2 *APIImages) bool {
|
creationAndTag := func(i1, i2 *APIImages) bool {
|
||||||
return i1.Created > i2.Created
|
return i1.Created > i2.Created || (i1.Created == i2.Created && i2.Tag > i1.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
sorter := &imageSorter{
|
sorter := &imageSorter{
|
||||||
images: images,
|
images: images,
|
||||||
by: creation}
|
by: creationAndTag}
|
||||||
|
|
||||||
sort.Sort(sorter)
|
sort.Sort(sorter)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerListOrderedImages(t *testing.T) {
|
func TestServerListOrderedImagesByCreationDate(t *testing.T) {
|
||||||
runtime := mkRuntime(t)
|
runtime := mkRuntime(t)
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
@ -28,3 +28,30 @@ func TestServerListOrderedImages(t *testing.T) {
|
||||||
t.Error("Expected []APIImges to be ordered by most recent creation date.")
|
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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue