Browse code

Move TestRunWithTooLowMemory to integration-cli

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2015/04/11 06:00:45
Showing 2 changed files
... ...
@@ -3493,3 +3493,15 @@ func TestRunPidHostWithChildIsKillable(t *testing.T) {
3493 3493
 	}
3494 3494
 	logDone("run - can kill container with pid-host and some childs of pid 1")
3495 3495
 }
3496
+
3497
+func TestRunWithTooSmallMemoryLimit(t *testing.T) {
3498
+	defer deleteAllContainers()
3499
+	// this memory limit is 1 byte less than the min, which is 4MB
3500
+	// https://github.com/docker/docker/blob/v1.5.0/daemon/create.go#L22
3501
+	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-m", "4194303", "busybox"))
3502
+	if err == nil || !strings.Contains(out, "Minimum memory limit allowed is 4MB") {
3503
+		t.Fatalf("expected run to fail when using too low a memory limit: %q", out)
3504
+	}
3505
+
3506
+	logDone("run - can't set too low memory limit")
3507
+}
... ...
@@ -1,6 +1,12 @@
1 1
 package docker
2 2
 
3
-import "testing"
3
+import (
4
+	"bytes"
5
+	"testing"
6
+
7
+	"github.com/docker/docker/builder"
8
+	"github.com/docker/docker/engine"
9
+)
4 10
 
5 11
 func TestCreateNumberHostname(t *testing.T) {
6 12
 	eng := NewTestEngine(t)
... ...
@@ -14,18 +20,84 @@ func TestCreateNumberHostname(t *testing.T) {
14 14
 	createTestContainer(eng, config, t)
15 15
 }
16 16
 
17
-func TestRunWithTooLowMemoryLimit(t *testing.T) {
17
+func TestCommit(t *testing.T) {
18 18
 	eng := NewTestEngine(t)
19
+	b := &builder.BuilderJob{Engine: eng}
20
+	b.Install()
19 21
 	defer mkDaemonFromEngine(eng, t).Nuke()
20 22
 
21
-	// Try to create a container with a memory limit of 1 byte less than the minimum allowed limit.
22
-	job := eng.Job("create")
23
-	job.Setenv("Image", unitTestImageID)
24
-	job.Setenv("Memory", "524287")
25
-	job.Setenv("CpuShares", "1000")
26
-	job.SetenvList("Cmd", []string{"/bin/cat"})
27
-	if err := job.Run(); err == nil {
28
-		t.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
23
+	config, _, _, err := parseRun([]string{unitTestImageID, "/bin/cat"})
24
+	if err != nil {
25
+		t.Fatal(err)
26
+	}
27
+
28
+	id := createTestContainer(eng, config, t)
29
+
30
+	job := eng.Job("commit", id)
31
+	job.Setenv("repo", "testrepo")
32
+	job.Setenv("tag", "testtag")
33
+	job.SetenvJson("config", config)
34
+	if err := job.Run(); err != nil {
35
+		t.Fatal(err)
36
+	}
37
+}
38
+
39
+func TestMergeConfigOnCommit(t *testing.T) {
40
+	eng := NewTestEngine(t)
41
+	b := &builder.BuilderJob{Engine: eng}
42
+	b.Install()
43
+	runtime := mkDaemonFromEngine(eng, t)
44
+	defer runtime.Nuke()
45
+
46
+	container1, _, _ := mkContainer(runtime, []string{"-e", "FOO=bar", unitTestImageID, "echo test > /tmp/foo"}, t)
47
+	defer runtime.Rm(container1)
48
+
49
+	config, _, _, err := parseRun([]string{container1.ID, "cat /tmp/foo"})
50
+	if err != nil {
51
+		t.Error(err)
52
+	}
53
+
54
+	job := eng.Job("commit", container1.ID)
55
+	job.Setenv("repo", "testrepo")
56
+	job.Setenv("tag", "testtag")
57
+	job.SetenvJson("config", config)
58
+	var outputBuffer = bytes.NewBuffer(nil)
59
+	job.Stdout.Add(outputBuffer)
60
+	if err := job.Run(); err != nil {
61
+		t.Error(err)
62
+	}
63
+
64
+	container2, _, _ := mkContainer(runtime, []string{engine.Tail(outputBuffer, 1)}, t)
65
+	defer runtime.Rm(container2)
66
+
67
+	job = eng.Job("container_inspect", container1.Name)
68
+	baseContainer, _ := job.Stdout.AddEnv()
69
+	if err := job.Run(); err != nil {
70
+		t.Error(err)
71
+	}
72
+
73
+	job = eng.Job("container_inspect", container2.Name)
74
+	commitContainer, _ := job.Stdout.AddEnv()
75
+	if err := job.Run(); err != nil {
76
+		t.Error(err)
77
+	}
78
+
79
+	baseConfig := baseContainer.GetSubEnv("Config")
80
+	commitConfig := commitContainer.GetSubEnv("Config")
81
+
82
+	if commitConfig.Get("Env") != baseConfig.Get("Env") {
83
+		t.Fatalf("Env config in committed container should be %v, was %v",
84
+			baseConfig.Get("Env"), commitConfig.Get("Env"))
85
+	}
86
+
87
+	if baseConfig.Get("Cmd") != "[\"echo test \\u003e /tmp/foo\"]" {
88
+		t.Fatalf("Cmd in base container should be [\"echo test \\u003e /tmp/foo\"], was %s",
89
+			baseConfig.Get("Cmd"))
90
+	}
91
+
92
+	if commitConfig.Get("Cmd") != "[\"cat /tmp/foo\"]" {
93
+		t.Fatalf("Cmd in committed container should be [\"cat /tmp/foo\"], was %s",
94
+			commitConfig.Get("Cmd"))
29 95
 	}
30 96
 }
31 97