2013-08-03 18:33:51 -04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-11-14 01:10:20 -05:00
|
|
|
"github.com/dotcloud/docker"
|
|
|
|
"github.com/dotcloud/docker/utils"
|
|
|
|
"io/ioutil"
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
images, err := srv.Images(true, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if images[0].Created < images[1].Created {
|
|
|
|
t.Error("Expected []APIImges to be ordered by most recent creation date.")
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
images, err := srv.Images(true, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-13 09:42:01 -04:00
|
|
|
if images[0].RepoTags[0] != "repo:zed" && images[0].RepoTags[0] != "repo:bar" {
|
|
|
|
t.Errorf("Expected []APIImges to be ordered by most recent creation date. %s", images)
|
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
|
|
|
|
}
|
2013-11-14 01:10:20 -05:00
|
|
|
return srv.ImageImport("-", "repo", name, archive, ioutil.Discard, utils.NewStreamFormatter(true))
|
2013-10-04 22:25:15 -04:00
|
|
|
}
|