1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/sorter_test.go

59 lines
1.3 KiB
Go
Raw Normal View History

package docker
import (
"github.com/dotcloud/docker"
"testing"
2013-10-13 09:42:01 -04:00
"time"
)
func TestServerListOrderedImagesByCreationDate(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()
srv := mkServerFromEngine(eng, t)
if err := generateImage("", srv); err != nil {
t.Fatal(err)
}
images := getImages(eng, t, true, "")
if images.Data[0].GetInt("Created") < images.Data[1].GetInt("Created") {
t.Error("Expected images to be ordered by most recent creation date.")
}
}
func TestServerListOrderedImagesByCreationDateAndTag(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()
srv := mkServerFromEngine(eng, t)
err := generateImage("bar", srv)
if err != nil {
t.Fatal(err)
}
2013-10-13 09:42:01 -04:00
time.Sleep(time.Second)
err = generateImage("zed", srv)
if err != nil {
t.Fatal(err)
}
images := getImages(eng, t, true, "")
if repoTags := images.Data[0].GetList("RepoTags"); repoTags[0] != "repo:zed" && repoTags[0] != "repo:bar" {
t.Errorf("Expected Images to be ordered by most recent creation date.")
}
}
func generateImage(name string, srv *docker.Server) error {
2013-10-13 09:42:01 -04:00
archive, err := fakeTar()
if err != nil {
return err
}
job := srv.Eng.Job("import", "-", "repo", name)
job.Stdin.Add(archive)
job.SetenvBool("json", true)
return job.Run()
}