2013-08-03 18:33:51 -04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2014-01-29 15:16:47 -05:00
|
|
|
"github.com/dotcloud/docker/engine"
|
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()
|
2013-08-03 18:33:51 -04:00
|
|
|
|
2014-01-29 15:16:47 -05:00
|
|
|
if err := generateImage("", eng); 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()
|
2013-08-18 01:11:34 -04:00
|
|
|
|
2014-01-29 15:16:47 -05:00
|
|
|
err := generateImage("bar", eng)
|
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)
|
|
|
|
|
2014-01-29 15:16:47 -05:00
|
|
|
err = generateImage("zed", eng)
|
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
|
|
|
|
2014-01-29 15:16:47 -05:00
|
|
|
func generateImage(name string, eng *engine.Engine) error {
|
2013-10-13 09:42:01 -04:00
|
|
|
archive, err := fakeTar()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-01-29 15:16:47 -05:00
|
|
|
job := eng.Job("import", "-", "repo", name)
|
2014-01-22 16:35:35 -05:00
|
|
|
job.Stdin.Add(archive)
|
|
|
|
job.SetenvBool("json", true)
|
|
|
|
return job.Run()
|
2013-10-04 22:25:15 -04:00
|
|
|
}
|