2013-05-06 16:59:33 +02:00
|
|
|
package docker
|
|
|
|
|
2015-04-10 22:41:43 +02:00
|
|
|
import "testing"
|
2013-05-06 16:59:33 +02:00
|
|
|
|
2014-01-30 00:45:55 +00:00
|
|
|
func TestCreateNumberHostname(t *testing.T) {
|
|
|
|
eng := NewTestEngine(t)
|
2014-04-17 14:43:01 -07:00
|
|
|
defer mkDaemonFromEngine(eng, t).Nuke()
|
2014-01-30 00:45:55 +00:00
|
|
|
|
2014-10-30 09:35:49 -07:00
|
|
|
config, _, _, err := parseRun([]string{"-h", "web.0", unitTestImageID, "echo test"})
|
2014-01-30 00:45:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
createTestContainer(eng, config, t)
|
|
|
|
}
|
|
|
|
|
2013-06-14 22:55:00 +03:00
|
|
|
func TestRunWithTooLowMemoryLimit(t *testing.T) {
|
2013-10-27 19:20:00 -07:00
|
|
|
eng := NewTestEngine(t)
|
2014-04-17 14:43:01 -07:00
|
|
|
defer mkDaemonFromEngine(eng, t).Nuke()
|
2013-10-08 19:15:29 +00:00
|
|
|
|
2013-06-14 22:55:00 +03:00
|
|
|
// Try to create a container with a memory limit of 1 byte less than the minimum allowed limit.
|
2013-10-27 19:20:00 -07:00
|
|
|
job := eng.Job("create")
|
2013-11-14 06:10:20 +00:00
|
|
|
job.Setenv("Image", unitTestImageID)
|
2013-10-27 19:20:00 -07:00
|
|
|
job.Setenv("Memory", "524287")
|
|
|
|
job.Setenv("CpuShares", "1000")
|
|
|
|
job.SetenvList("Cmd", []string{"/bin/cat"})
|
|
|
|
if err := job.Run(); err == nil {
|
2013-06-14 22:55:00 +03:00
|
|
|
t.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
|
|
|
|
}
|
|
|
|
}
|
2013-07-16 14:38:18 +00:00
|
|
|
|
2013-09-06 16:16:10 -04:00
|
|
|
func TestImagesFilter(t *testing.T) {
|
2013-11-14 06:10:20 +00:00
|
|
|
eng := NewTestEngine(t)
|
2014-04-17 14:43:01 -07:00
|
|
|
defer nuke(mkDaemonFromEngine(eng, t))
|
2013-09-06 16:16:10 -04:00
|
|
|
|
2013-12-11 17:52:41 -08:00
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:52:41 -08:00
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-12-11 17:52:41 -08:00
|
|
|
|
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images := getImages(eng, t, false, "utest*/*")
|
2013-09-06 16:16:10 -04:00
|
|
|
|
2015-04-07 18:57:54 -07:00
|
|
|
if len(images[0].RepoTags) != 2 {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal("incorrect number of matches returned")
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getImages(eng, t, false, "utest")
|
2013-09-06 16:16:10 -04:00
|
|
|
|
2015-04-07 18:57:54 -07:00
|
|
|
if len(images[0].RepoTags) != 1 {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal("incorrect number of matches returned")
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getImages(eng, t, false, "utest*")
|
2013-09-06 16:16:10 -04:00
|
|
|
|
2015-04-07 18:57:54 -07:00
|
|
|
if len(images[0].RepoTags) != 1 {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal("incorrect number of matches returned")
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getImages(eng, t, false, "*5000*/*")
|
2013-09-06 16:16:10 -04:00
|
|
|
|
2015-04-07 18:57:54 -07:00
|
|
|
if len(images[0].RepoTags) != 1 {
|
2013-09-06 16:16:10 -04:00
|
|
|
t.Fatal("incorrect number of matches returned")
|
|
|
|
}
|
|
|
|
}
|