2013-05-06 14:59:33 +00:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-11-14 06:10:20 +00:00
|
|
|
"github.com/dotcloud/docker"
|
2014-02-21 23:15:28 +00:00
|
|
|
"github.com/dotcloud/docker/engine"
|
2014-02-12 04:04:39 +00:00
|
|
|
"github.com/dotcloud/docker/runconfig"
|
2013-11-13 19:25:55 +00:00
|
|
|
"strings"
|
2013-05-06 14:59:33 +00:00
|
|
|
"testing"
|
2014-01-22 00:38:17 +00:00
|
|
|
"time"
|
2013-05-06 14:59:33 +00:00
|
|
|
)
|
|
|
|
|
2013-12-12 01:52:41 +00:00
|
|
|
func TestImageTagImageDelete(t *testing.T) {
|
2013-11-14 06:10:20 +00:00
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2013-11-14 06:10:20 +00:00
|
|
|
srv := mkServerFromEngine(eng, t)
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
initialImages := getAllImages(eng, t)
|
2013-12-12 01:52:41 +00:00
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
|
2013-05-15 13:11:39 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-07-31 07:56:53 +00:00
|
|
|
|
2013-12-12 01:52:41 +00:00
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
|
2013-05-15 13:11:39 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-12-12 01:52:41 +00:00
|
|
|
|
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
|
2013-05-15 13:11:39 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images := getAllImages(eng, t)
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
nExpected := len(initialImages.Data[0].GetList("RepoTags")) + 3
|
|
|
|
nActual := len(images.Data[0].GetList("RepoTags"))
|
|
|
|
if nExpected != nActual {
|
|
|
|
t.Errorf("Expected %d images, %d found", nExpected, nActual)
|
2013-05-15 13:11:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 02:44:17 +00:00
|
|
|
if err := srv.DeleteImage("utest/docker:tag2", engine.NewTable("", 0), true, false); err != nil {
|
2013-05-15 13:11:39 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getAllImages(eng, t)
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
nExpected = len(initialImages.Data[0].GetList("RepoTags")) + 2
|
|
|
|
nActual = len(images.Data[0].GetList("RepoTags"))
|
|
|
|
if nExpected != nActual {
|
|
|
|
t.Errorf("Expected %d images, %d found", nExpected, nActual)
|
2013-05-15 13:11:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 02:44:17 +00:00
|
|
|
if err := srv.DeleteImage("utest:5000/docker:tag3", engine.NewTable("", 0), true, false); err != nil {
|
2013-05-15 13:11:39 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getAllImages(eng, t)
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
nExpected = len(initialImages.Data[0].GetList("RepoTags")) + 1
|
|
|
|
nActual = len(images.Data[0].GetList("RepoTags"))
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2014-02-11 02:44:17 +00:00
|
|
|
if err := srv.DeleteImage("utest:tag1", engine.NewTable("", 0), true, false); err != nil {
|
2013-05-15 13:11:39 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getAllImages(eng, t)
|
2013-05-15 13:11:39 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if images.Len() != initialImages.Len() {
|
|
|
|
t.Errorf("Expected %d image, %d found", initialImages.Len(), images.Len())
|
2013-05-15 13:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-06 14:59:33 +00:00
|
|
|
func TestCreateRm(t *testing.T) {
|
2013-10-28 02:20:00 +00:00
|
|
|
eng := NewTestEngine(t)
|
2013-11-14 06:10:20 +00:00
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-05-06 14:59:33 +00:00
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, _, _, err := runconfig.Parse([]string{unitTestImageID, "echo test"}, nil)
|
2013-05-06 14:59:33 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:20:00 +00:00
|
|
|
id := createTestContainer(eng, config, t)
|
2013-05-06 14:59:33 +00:00
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job := eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err := job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outs.Data) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(outs.Data))
|
2013-05-06 14:59:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job = eng.Job("container_delete", id)
|
2013-12-11 23:23:38 +00:00
|
|
|
job.SetenvBool("removeVolume", true)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job = eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err = job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outs.Data) != 0 {
|
|
|
|
t.Errorf("Expected 0 container, %v found", len(outs.Data))
|
2013-05-06 14:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:45:55 +00:00
|
|
|
func TestCreateNumberHostname(t *testing.T) {
|
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, _, _, err := runconfig.Parse([]string{"-h", "web.0", unitTestImageID, "echo test"}, nil)
|
2014-01-30 00:45:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
createTestContainer(eng, config, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateNumberUsername(t *testing.T) {
|
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, _, _, err := runconfig.Parse([]string{"-u", "1002", unitTestImageID, "echo test"}, nil)
|
2014-01-30 00:45:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
createTestContainer(eng, config, t)
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:35:47 +00:00
|
|
|
func TestCreateRmVolumes(t *testing.T) {
|
2013-10-27 07:13:45 +00:00
|
|
|
eng := NewTestEngine(t)
|
2013-11-14 06:10:20 +00:00
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-10-08 16:35:47 +00:00
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, hostConfig, _, err := runconfig.Parse([]string{"-v", "/srv", unitTestImageID, "echo", "test"}, nil)
|
2013-10-08 16:35:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:20:00 +00:00
|
|
|
id := createTestContainer(eng, config, t)
|
2013-10-08 16:35:47 +00:00
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job := eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err := job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
2013-10-08 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
if len(outs.Data) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(outs.Data))
|
|
|
|
}
|
|
|
|
|
|
|
|
job = eng.Job("start", id)
|
2013-10-27 02:24:01 +00:00
|
|
|
if err := job.ImportEnv(hostConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
2013-10-08 16:35:47 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:36:50 +00:00
|
|
|
job = eng.Job("stop", id)
|
|
|
|
job.SetenvInt("t", 1)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-10-08 16:35:47 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:23:38 +00:00
|
|
|
job = eng.Job("container_delete", id)
|
|
|
|
job.SetenvBool("removeVolume", true)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-10-08 16:35:47 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job = eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err = job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outs.Data) != 0 {
|
|
|
|
t.Errorf("Expected 0 container, %v found", len(outs.Data))
|
2013-10-08 16:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:20:56 +00:00
|
|
|
func TestCommit(t *testing.T) {
|
2013-10-28 02:20:00 +00:00
|
|
|
eng := NewTestEngine(t)
|
2013-11-14 06:10:20 +00:00
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-07-25 15:20:56 +00:00
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, _, _, err := runconfig.Parse([]string{unitTestImageID, "/bin/cat"}, nil)
|
2013-07-25 15:20:56 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:20:00 +00:00
|
|
|
id := createTestContainer(eng, config, t)
|
2013-07-25 15:20:56 +00:00
|
|
|
|
2013-12-13 22:29:27 +00:00
|
|
|
job := eng.Job("commit", id)
|
2013-12-12 01:03:48 +00:00
|
|
|
job.Setenv("repo", "testrepo")
|
|
|
|
job.Setenv("tag", "testtag")
|
|
|
|
job.SetenvJson("config", config)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-07-25 15:20:56 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-22 00:38:17 +00:00
|
|
|
func TestRestartKillWait(t *testing.T) {
|
|
|
|
eng := NewTestEngine(t)
|
|
|
|
srv := mkServerFromEngine(eng, t)
|
|
|
|
runtime := mkRuntimeFromEngine(eng, t)
|
|
|
|
defer runtime.Nuke()
|
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, hostConfig, _, err := runconfig.Parse([]string{"-i", unitTestImageID, "/bin/cat"}, nil)
|
2014-01-22 00:38:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
id := createTestContainer(eng, config, t)
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job := eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err := job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
2014-01-22 00:38:17 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
if len(outs.Data) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(outs.Data))
|
|
|
|
}
|
|
|
|
|
|
|
|
job = eng.Job("start", id)
|
2014-01-22 00:38:17 +00:00
|
|
|
if err := job.ImportEnv(hostConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
job = eng.Job("kill", id)
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-02-24 19:22:48 +00:00
|
|
|
eng = newTestEngine(t, false, eng.Root())
|
2014-01-22 00:38:17 +00:00
|
|
|
srv = mkServerFromEngine(eng, t)
|
2014-01-16 22:00:18 +00:00
|
|
|
|
|
|
|
job = srv.Eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err = job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outs.Data) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(outs.Data))
|
2014-01-22 00:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(t, "Waiting on stopped container timedout", 5*time.Second, func() {
|
2014-01-29 20:31:49 +00:00
|
|
|
job = srv.Eng.Job("wait", outs.Data[0].Get("Id"))
|
2014-01-22 00:38:17 +00:00
|
|
|
var statusStr string
|
|
|
|
job.Stdout.AddString(&statusStr)
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-05-06 14:59:33 +00:00
|
|
|
func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
2013-10-27 07:13:45 +00:00
|
|
|
eng := NewTestEngine(t)
|
2013-10-27 02:24:01 +00:00
|
|
|
srv := mkServerFromEngine(eng, t)
|
2013-11-14 06:10:20 +00:00
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-05-06 14:59:33 +00:00
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, hostConfig, _, err := runconfig.Parse([]string{"-i", unitTestImageID, "/bin/cat"}, nil)
|
2013-05-06 14:59:33 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:20:00 +00:00
|
|
|
id := createTestContainer(eng, config, t)
|
2013-05-06 14:59:33 +00:00
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job := srv.Eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err := job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outs.Data) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(outs.Data))
|
2013-05-06 14:59:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job = eng.Job("start", id)
|
2013-10-27 02:24:01 +00:00
|
|
|
if err := job.ImportEnv(hostConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-01-07 01:34:51 +00:00
|
|
|
job = eng.Job("restart", id)
|
|
|
|
job.SetenvInt("t", 15)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:36:50 +00:00
|
|
|
job = eng.Job("stop", id)
|
|
|
|
job.SetenvInt("t", 15)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-27 02:24:01 +00:00
|
|
|
job = eng.Job("start", id)
|
|
|
|
if err := job.ImportEnv(hostConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-11-17 00:26:42 +00:00
|
|
|
if err := eng.Job("kill", id).Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-05-25 01:31:47 +00:00
|
|
|
// FIXME: this failed once with a race condition ("Unable to remove filesystem for xxx: directory not empty")
|
2013-12-11 23:23:38 +00:00
|
|
|
job = eng.Job("container_delete", id)
|
|
|
|
job.SetenvBool("removeVolume", true)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-05-06 14:59:33 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job = srv.Eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err = job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outs.Data) != 0 {
|
|
|
|
t.Errorf("Expected 0 container, %v found", len(outs.Data))
|
2013-05-06 14:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-14 19:55:00 +00:00
|
|
|
|
|
|
|
func TestRunWithTooLowMemoryLimit(t *testing.T) {
|
2013-10-28 02:20:00 +00:00
|
|
|
eng := NewTestEngine(t)
|
2013-11-14 06:10:20 +00:00
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-10-08 19:15:29 +00:00
|
|
|
|
2013-06-14 19:55:00 +00:00
|
|
|
// Try to create a container with a memory limit of 1 byte less than the minimum allowed limit.
|
2013-10-28 02:20:00 +00:00
|
|
|
job := eng.Job("create")
|
2013-11-14 06:10:20 +00:00
|
|
|
job.Setenv("Image", unitTestImageID)
|
2013-10-28 02:20:00 +00:00
|
|
|
job.Setenv("Memory", "524287")
|
|
|
|
job.Setenv("CpuShares", "1000")
|
|
|
|
job.SetenvList("Cmd", []string{"/bin/cat"})
|
|
|
|
var id string
|
2013-11-20 07:37:03 +00:00
|
|
|
job.Stdout.AddString(&id)
|
2013-10-28 02:20:00 +00:00
|
|
|
if err := job.Run(); err == nil {
|
2013-06-14 19:55:00 +00: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-07-26 10:01:41 +00:00
|
|
|
func TestRmi(t *testing.T) {
|
2013-10-27 07:13:45 +00:00
|
|
|
eng := NewTestEngine(t)
|
2013-10-27 02:24:01 +00:00
|
|
|
srv := mkServerFromEngine(eng, t)
|
2013-11-14 06:10:20 +00:00
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
2013-07-26 10:01:41 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
initialImages := getAllImages(eng, t)
|
2013-07-26 10:01:41 +00:00
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config, hostConfig, _, err := runconfig.Parse([]string{unitTestImageID, "echo", "test"}, nil)
|
2013-07-26 10:01:41 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:20:00 +00:00
|
|
|
containerID := createTestContainer(eng, config, t)
|
2013-07-26 10:01:41 +00:00
|
|
|
|
|
|
|
//To remove
|
2013-10-27 02:24:01 +00:00
|
|
|
job := eng.Job("start", containerID)
|
|
|
|
if err := job.ImportEnv(hostConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-11-25 01:05:59 +00:00
|
|
|
if err := eng.Job("wait", containerID).Run(); err != nil {
|
2013-11-12 16:21:02 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-13 22:29:27 +00:00
|
|
|
job = eng.Job("commit", containerID)
|
2013-12-12 01:03:48 +00:00
|
|
|
job.Setenv("repo", "test")
|
|
|
|
var imageID string
|
|
|
|
job.Stdout.AddString(&imageID)
|
|
|
|
if err := job.Run(); err != nil {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 01:52:41 +00:00
|
|
|
if err := eng.Job("tag", imageID, "test", "0.1").Run(); err != nil {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:20:00 +00:00
|
|
|
containerID = createTestContainer(eng, config, t)
|
2013-07-26 10:01:41 +00:00
|
|
|
|
|
|
|
//To remove
|
2013-10-27 02:24:01 +00:00
|
|
|
job = eng.Job("start", containerID)
|
|
|
|
if err := job.ImportEnv(hostConfig); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-11-25 01:05:59 +00:00
|
|
|
if err := eng.Job("wait", containerID).Run(); err != nil {
|
2013-11-12 16:21:02 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-13 22:29:27 +00:00
|
|
|
job = eng.Job("commit", containerID)
|
2013-12-12 01:03:48 +00:00
|
|
|
job.Setenv("repo", "test")
|
|
|
|
if err := job.Run(); err != nil {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images := getAllImages(eng, t)
|
2013-07-26 10:01:41 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if images.Len()-initialImages.Len() != 2 {
|
|
|
|
t.Fatalf("Expected 2 new images, found %d.", images.Len()-initialImages.Len())
|
2013-07-26 10:01:41 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 02:44:17 +00:00
|
|
|
if err = srv.DeleteImage(imageID, engine.NewTable("", 0), true, false); err != nil {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images = getAllImages(eng, t)
|
2013-07-26 10:01:41 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if images.Len()-initialImages.Len() != 1 {
|
|
|
|
t.Fatalf("Expected 1 new image, found %d.", images.Len()-initialImages.Len())
|
2013-07-26 10:01:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
for _, image := range images.Data {
|
2014-01-29 20:31:49 +00:00
|
|
|
if strings.Contains(unitTestImageID, image.Get("Id")) {
|
2013-07-26 10:01:41 +00:00
|
|
|
continue
|
|
|
|
}
|
2013-12-12 22:39:35 +00:00
|
|
|
if image.GetList("RepoTags")[0] == "<none>:<none>" {
|
2013-07-26 10:01:41 +00:00
|
|
|
t.Fatalf("Expected tagged image, got untagged one.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 20:16:10 +00:00
|
|
|
|
|
|
|
func TestImagesFilter(t *testing.T) {
|
2013-11-14 06:10:20 +00:00
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer nuke(mkRuntimeFromEngine(eng, t))
|
2013-09-06 20:16:10 +00:00
|
|
|
|
2013-12-12 01:52:41 +00:00
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
|
2013-09-06 20:16:10 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 01:52:41 +00:00
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
|
2013-09-06 20:16:10 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-12-12 01:52:41 +00:00
|
|
|
|
|
|
|
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
|
2013-09-06 20:16:10 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
images := getImages(eng, t, false, "utest*/*")
|
2013-09-06 20:16:10 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if len(images.Data[0].GetList("RepoTags")) != 2 {
|
2013-09-06 20:16:10 +00: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 20:16:10 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if len(images.Data[0].GetList("RepoTags")) != 1 {
|
2013-09-06 20:16:10 +00: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 20:16:10 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if len(images.Data[0].GetList("RepoTags")) != 1 {
|
2013-09-06 20:16:10 +00: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 20:16:10 +00:00
|
|
|
|
2013-12-12 22:39:35 +00:00
|
|
|
if len(images.Data[0].GetList("RepoTags")) != 1 {
|
2013-09-06 20:16:10 +00:00
|
|
|
t.Fatal("incorrect number of matches returned")
|
|
|
|
}
|
|
|
|
}
|
2013-11-08 05:34:54 +00:00
|
|
|
|
|
|
|
func TestImageInsert(t *testing.T) {
|
2013-11-14 06:10:20 +00:00
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
|
|
|
srv := mkServerFromEngine(eng, t)
|
2013-11-08 05:34:54 +00:00
|
|
|
|
|
|
|
// bad image name fails
|
2014-01-09 18:06:16 +00:00
|
|
|
if err := srv.Eng.Job("insert", "foo", "https://www.docker.io/static/img/docker-top-logo.png", "/foo").Run(); err == nil {
|
2013-11-08 05:34:54 +00:00
|
|
|
t.Fatal("expected an error and got none")
|
|
|
|
}
|
|
|
|
|
|
|
|
// bad url fails
|
2014-01-09 18:06:16 +00:00
|
|
|
if err := srv.Eng.Job("insert", unitTestImageID, "http://bad_host_name_that_will_totally_fail.com/", "/foo").Run(); err == nil {
|
2013-11-08 05:34:54 +00:00
|
|
|
t.Fatal("expected an error and got none")
|
|
|
|
}
|
|
|
|
|
|
|
|
// success returns nil
|
2014-01-09 18:06:16 +00:00
|
|
|
if err := srv.Eng.Job("insert", unitTestImageID, "https://www.docker.io/static/img/docker-top-logo.png", "/foo").Run(); err != nil {
|
2013-11-08 05:34:54 +00:00
|
|
|
t.Fatalf("expected no error, but got %v", err)
|
|
|
|
}
|
|
|
|
}
|
2013-12-16 21:29:43 +00:00
|
|
|
|
2014-01-26 23:10:34 +00:00
|
|
|
func TestListContainers(t *testing.T) {
|
|
|
|
eng := NewTestEngine(t)
|
|
|
|
srv := mkServerFromEngine(eng, t)
|
|
|
|
defer mkRuntimeFromEngine(eng, t).Nuke()
|
|
|
|
|
2014-02-12 04:04:39 +00:00
|
|
|
config := runconfig.Config{
|
2014-01-26 23:10:34 +00:00
|
|
|
Image: unitTestImageID,
|
|
|
|
Cmd: []string{"/bin/sh", "-c", "cat"},
|
|
|
|
OpenStdin: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
firstID := createTestContainer(eng, &config, t)
|
|
|
|
secondID := createTestContainer(eng, &config, t)
|
|
|
|
thirdID := createTestContainer(eng, &config, t)
|
|
|
|
fourthID := createTestContainer(eng, &config, t)
|
|
|
|
defer func() {
|
|
|
|
containerKill(eng, firstID, t)
|
|
|
|
containerKill(eng, secondID, t)
|
|
|
|
containerKill(eng, fourthID, t)
|
|
|
|
containerWait(eng, firstID, t)
|
|
|
|
containerWait(eng, secondID, t)
|
|
|
|
containerWait(eng, fourthID, t)
|
|
|
|
}()
|
|
|
|
|
|
|
|
startContainer(eng, firstID, t)
|
|
|
|
startContainer(eng, secondID, t)
|
|
|
|
startContainer(eng, fourthID, t)
|
|
|
|
|
|
|
|
// all
|
|
|
|
if !assertContainerList(srv, true, -1, "", "", []string{fourthID, thirdID, secondID, firstID}) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// running
|
|
|
|
if !assertContainerList(srv, false, -1, "", "", []string{fourthID, secondID, firstID}) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// from here 'all' flag is ignored
|
|
|
|
|
|
|
|
// limit
|
|
|
|
expected := []string{fourthID, thirdID}
|
|
|
|
if !assertContainerList(srv, true, 2, "", "", expected) ||
|
|
|
|
!assertContainerList(srv, false, 2, "", "", expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// since
|
|
|
|
expected = []string{fourthID, thirdID, secondID}
|
|
|
|
if !assertContainerList(srv, true, -1, firstID, "", expected) ||
|
|
|
|
!assertContainerList(srv, false, -1, firstID, "", expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// before
|
|
|
|
expected = []string{secondID, firstID}
|
|
|
|
if !assertContainerList(srv, true, -1, "", thirdID, expected) ||
|
|
|
|
!assertContainerList(srv, false, -1, "", thirdID, expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// since & before
|
|
|
|
expected = []string{thirdID, secondID}
|
|
|
|
if !assertContainerList(srv, true, -1, firstID, fourthID, expected) ||
|
|
|
|
!assertContainerList(srv, false, -1, firstID, fourthID, expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// since & limit
|
|
|
|
expected = []string{fourthID, thirdID}
|
|
|
|
if !assertContainerList(srv, true, 2, firstID, "", expected) ||
|
|
|
|
!assertContainerList(srv, false, 2, firstID, "", expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// before & limit
|
|
|
|
expected = []string{thirdID}
|
|
|
|
if !assertContainerList(srv, true, 1, "", fourthID, expected) ||
|
|
|
|
!assertContainerList(srv, false, 1, "", fourthID, expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// since & before & limit
|
|
|
|
expected = []string{thirdID}
|
|
|
|
if !assertContainerList(srv, true, 1, firstID, fourthID, expected) ||
|
|
|
|
!assertContainerList(srv, false, 1, firstID, fourthID, expected) {
|
|
|
|
t.Error("Container list is not in the correct order")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertContainerList(srv *docker.Server, all bool, limit int, since, before string, expected []string) bool {
|
|
|
|
job := srv.Eng.Job("containers")
|
|
|
|
job.SetenvBool("all", all)
|
|
|
|
job.SetenvInt("limit", limit)
|
|
|
|
job.Setenv("since", since)
|
|
|
|
job.Setenv("before", before)
|
|
|
|
outs, err := job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(outs.Data) != len(expected) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i := 0; i < len(outs.Data); i++ {
|
2014-01-29 20:31:49 +00:00
|
|
|
if outs.Data[i].Get("Id") != expected[i] {
|
2014-01-26 23:10:34 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2013-12-16 21:29:43 +00:00
|
|
|
// Regression test for being able to untag an image with an existing
|
|
|
|
// container
|
|
|
|
func TestDeleteTagWithExistingContainers(t *testing.T) {
|
|
|
|
eng := NewTestEngine(t)
|
|
|
|
defer nuke(mkRuntimeFromEngine(eng, t))
|
|
|
|
|
|
|
|
srv := mkServerFromEngine(eng, t)
|
|
|
|
|
|
|
|
// Tag the image
|
|
|
|
if err := eng.Job("tag", unitTestImageID, "utest", "tag1").Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a container from the image
|
2014-02-12 04:04:39 +00:00
|
|
|
config, _, _, err := runconfig.Parse([]string{unitTestImageID, "echo test"}, nil)
|
2013-12-16 21:29:43 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
id := createNamedTestContainer(eng, config, t, "testingtags")
|
|
|
|
if id == "" {
|
|
|
|
t.Fatal("No id returned")
|
|
|
|
}
|
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
job := srv.Eng.Job("containers")
|
|
|
|
job.SetenvBool("all", true)
|
|
|
|
outs, err := job.Stdout.AddListTable()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-12-16 21:29:43 +00:00
|
|
|
|
2014-01-16 22:00:18 +00:00
|
|
|
if len(outs.Data) != 1 {
|
|
|
|
t.Fatalf("Expected 1 container got %d", len(outs.Data))
|
2013-12-16 21:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to remove the tag
|
2014-02-11 02:44:17 +00:00
|
|
|
imgs := engine.NewTable("", 0)
|
|
|
|
if err := srv.DeleteImage("utest:tag1", imgs, true, false); err != nil {
|
2013-12-16 21:29:43 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-01-17 02:40:33 +00:00
|
|
|
if len(imgs.Data) != 1 {
|
|
|
|
t.Fatalf("Should only have deleted one untag %d", len(imgs.Data))
|
2013-12-16 21:29:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 01:44:53 +00:00
|
|
|
if untag := imgs.Data[0].Get("Untagged"); untag != "utest:tag1" {
|
2014-01-17 02:40:33 +00:00
|
|
|
t.Fatalf("Expected %s got %s", unitTestImageID, untag)
|
2013-12-16 21:29:43 +00:00
|
|
|
}
|
|
|
|
}
|