2013-08-03 18:33:51 -04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-11-14 01:10:20 -05:00
|
|
|
"github.com/dotcloud/docker"
|
2013-08-03 18:33:51 -04:00
|
|
|
"testing"
|
2013-10-13 09:42:01 -04:00
|
|
|
"time"
|
2013-08-03 18:33:51 -04:00
|
|
|
)
|
|
|
|
|
2013-08-18 01:11:34 -04:00
|
|
|
func TestServerListOrderedImagesByCreationDate(t *testing.T) {
|
2013-11-14 01:10:20 -05:00
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
|
|
|
srv := mkServerFromEngine(eng, t)
|
2013-08-03 18:33:51 -04:00
|
|
|
|
2013-11-14 01:10:20 -05:00
|
|
|
if err := generateImage("", srv); err != nil {
|
2013-08-03 18:33:51 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 17:39:35 -05:00
|
|
|
images := getImages(eng, t, true, "")
|
2013-08-03 18:33:51 -04:00
|
|
|
|
2013-12-12 17:39:35 -05:00
|
|
|
if images.Data[0].GetInt("Created") < images.Data[1].GetInt("Created") {
|
|
|
|
t.Error("Expected images to be ordered by most recent creation date.")
|
2013-08-03 18:33:51 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-18 01:11:34 -04:00
|
|
|
|
|
|
|
func TestServerListOrderedImagesByCreationDateAndTag(t *testing.T) {
|
2013-11-14 01:10:20 -05:00
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
|
|
|
srv := mkServerFromEngine(eng, t)
|
2013-08-18 01:11:34 -04:00
|
|
|
|
2013-11-14 01:10:20 -05:00
|
|
|
err := generateImage("bar", srv)
|
2013-08-18 01:11:34 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-10-13 09:42:01 -04:00
|
|
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
2013-11-14 01:10:20 -05:00
|
|
|
err = generateImage("zed", srv)
|
2013-08-18 01:11:34 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 17:39:35 -05:00
|
|
|
images := getImages(eng, t, true, "")
|
2013-08-18 01:11:34 -04:00
|
|
|
|
2013-12-13 13:26:00 -05:00
|
|
|
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.")
|
2013-08-18 01:11:34 -04:00
|
|
|
}
|
|
|
|
}
|
2013-10-04 22:25:15 -04:00
|
|
|
|
2013-11-14 01:10:20 -05:00
|
|
|
func generateImage(name string, srv *docker.Server) error {
|
2013-10-13 09:42:01 -04:00
|
|
|
archive, err := fakeTar()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-01-22 16:35:35 -05:00
|
|
|
job := srv.Eng.Job("import", "-", "repo", name)
|
|
|
|
job.Stdin.Add(archive)
|
|
|
|
job.SetenvBool("json", true)
|
|
|
|
return job.Run()
|
2013-10-04 22:25:15 -04:00
|
|
|
}
|