Browse code

Port volumes and exit code tests Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/04/18 11:34:10
Showing 2 changed files
... ...
@@ -408,3 +408,31 @@ func TestVerifyContainerID(t *testing.T) {
408 408
 
409 409
 	logDone("run - verify container ID")
410 410
 }
411
+
412
+// Test that creating a container with a volume doesn't crash. Regression test for #995.
413
+func TestCreateVolume(t *testing.T) {
414
+	cmd := exec.Command(dockerBinary, "run", "-v", "/var/lib/data", "busybox", "true")
415
+	if _, err := runCommand(cmd); err != nil {
416
+		t.Fatal(err)
417
+	}
418
+
419
+	deleteAllContainers()
420
+
421
+	logDone("run - create docker mangaed volume")
422
+}
423
+
424
+func TestExitCode(t *testing.T) {
425
+	cmd := exec.Command(dockerBinary, "run", "busybox", "/bin/sh", "-c", "exit 72")
426
+
427
+	exit, err := runCommand(cmd)
428
+	if err == nil {
429
+		t.Fatal("should not have a non nil error")
430
+	}
431
+	if exit != 72 {
432
+		t.Fatalf("expected exit code 72 received %d", exit)
433
+	}
434
+
435
+	deleteAllContainers()
436
+
437
+	logDone("run - correct exit code")
438
+}
... ...
@@ -16,36 +16,6 @@ import (
16 16
 	"time"
17 17
 )
18 18
 
19
-func TestStart(t *testing.T) {
20
-	daemon := mkDaemon(t)
21
-	defer nuke(daemon)
22
-	container, _, _ := mkContainer(daemon, []string{"-i", "_", "/bin/cat"}, t)
23
-	defer daemon.Destroy(container)
24
-
25
-	cStdin, err := container.StdinPipe()
26
-	if err != nil {
27
-		t.Fatal(err)
28
-	}
29
-
30
-	if err := container.Start(); err != nil {
31
-		t.Fatal(err)
32
-	}
33
-
34
-	// Give some time to the process to start
35
-	container.WaitTimeout(500 * time.Millisecond)
36
-
37
-	if !container.State.IsRunning() {
38
-		t.Errorf("Container should be running")
39
-	}
40
-	if err := container.Start(); err != nil {
41
-		t.Fatalf("A running container should be able to be started")
42
-	}
43
-
44
-	// Try to avoid the timeout in destroy. Best effort, don't check error
45
-	cStdin.Close()
46
-	container.WaitTimeout(2 * time.Second)
47
-}
48
-
49 19
 func TestCpuShares(t *testing.T) {
50 20
 	_, err1 := os.Stat("/sys/fs/cgroup/cpuacct,cpu")
51 21
 	_, err2 := os.Stat("/sys/fs/cgroup/cpu,cpuacct")
... ...
@@ -81,46 +51,6 @@ func TestCpuShares(t *testing.T) {
81 81
 	container.WaitTimeout(2 * time.Second)
82 82
 }
83 83
 
84
-func TestRun(t *testing.T) {
85
-	daemon := mkDaemon(t)
86
-	defer nuke(daemon)
87
-	container, _, _ := mkContainer(daemon, []string{"_", "ls", "-al"}, t)
88
-	defer daemon.Destroy(container)
89
-
90
-	if container.State.IsRunning() {
91
-		t.Errorf("Container shouldn't be running")
92
-	}
93
-	if err := container.Run(); err != nil {
94
-		t.Fatal(err)
95
-	}
96
-	if container.State.IsRunning() {
97
-		t.Errorf("Container shouldn't be running")
98
-	}
99
-}
100
-
101
-func TestOutput(t *testing.T) {
102
-	daemon := mkDaemon(t)
103
-	defer nuke(daemon)
104
-	container, _, err := daemon.Create(
105
-		&runconfig.Config{
106
-			Image: GetTestImage(daemon).ID,
107
-			Cmd:   []string{"echo", "-n", "foobar"},
108
-		},
109
-		"",
110
-	)
111
-	if err != nil {
112
-		t.Fatal(err)
113
-	}
114
-	defer daemon.Destroy(container)
115
-	output, err := container.Output()
116
-	if err != nil {
117
-		t.Fatal(err)
118
-	}
119
-	if string(output) != "foobar" {
120
-		t.Fatalf("%s != %s", string(output), "foobar")
121
-	}
122
-}
123
-
124 84
 func TestKillDifferentUser(t *testing.T) {
125 85
 	daemon := mkDaemon(t)
126 86
 	defer nuke(daemon)
... ...
@@ -179,119 +109,6 @@ func TestKillDifferentUser(t *testing.T) {
179 179
 	}
180 180
 }
181 181
 
182
-// Test that creating a container with a volume doesn't crash. Regression test for #995.
183
-func TestCreateVolume(t *testing.T) {
184
-	eng := NewTestEngine(t)
185
-	daemon := mkDaemonFromEngine(eng, t)
186
-	defer nuke(daemon)
187
-
188
-	config, hc, _, err := runconfig.Parse([]string{"-v", "/var/lib/data", unitTestImageID, "echo", "hello", "world"}, nil)
189
-	if err != nil {
190
-		t.Fatal(err)
191
-	}
192
-	jobCreate := eng.Job("create")
193
-	if err := jobCreate.ImportEnv(config); err != nil {
194
-		t.Fatal(err)
195
-	}
196
-	var id string
197
-	jobCreate.Stdout.AddString(&id)
198
-	if err := jobCreate.Run(); err != nil {
199
-		t.Fatal(err)
200
-	}
201
-	jobStart := eng.Job("start", id)
202
-	if err := jobStart.ImportEnv(hc); err != nil {
203
-		t.Fatal(err)
204
-	}
205
-	if err := jobStart.Run(); err != nil {
206
-		t.Fatal(err)
207
-	}
208
-	// FIXME: this hack can be removed once Wait is a job
209
-	c := daemon.Get(id)
210
-	if c == nil {
211
-		t.Fatalf("Couldn't retrieve container %s from daemon", id)
212
-	}
213
-	c.WaitTimeout(500 * time.Millisecond)
214
-	c.Wait()
215
-}
216
-
217
-func TestKill(t *testing.T) {
218
-	daemon := mkDaemon(t)
219
-	defer nuke(daemon)
220
-	container, _, err := daemon.Create(&runconfig.Config{
221
-		Image: GetTestImage(daemon).ID,
222
-		Cmd:   []string{"sleep", "2"},
223
-	},
224
-		"",
225
-	)
226
-	if err != nil {
227
-		t.Fatal(err)
228
-	}
229
-	defer daemon.Destroy(container)
230
-
231
-	if container.State.IsRunning() {
232
-		t.Errorf("Container shouldn't be running")
233
-	}
234
-	if err := container.Start(); err != nil {
235
-		t.Fatal(err)
236
-	}
237
-
238
-	// Give some time to lxc to spawn the process
239
-	container.WaitTimeout(500 * time.Millisecond)
240
-
241
-	if !container.State.IsRunning() {
242
-		t.Errorf("Container should be running")
243
-	}
244
-	if err := container.Kill(); err != nil {
245
-		t.Fatal(err)
246
-	}
247
-	if container.State.IsRunning() {
248
-		t.Errorf("Container shouldn't be running")
249
-	}
250
-	container.Wait()
251
-	if container.State.IsRunning() {
252
-		t.Errorf("Container shouldn't be running")
253
-	}
254
-	// Try stopping twice
255
-	if err := container.Kill(); err != nil {
256
-		t.Fatal(err)
257
-	}
258
-}
259
-
260
-func TestExitCode(t *testing.T) {
261
-	daemon := mkDaemon(t)
262
-	defer nuke(daemon)
263
-
264
-	trueContainer, _, err := daemon.Create(&runconfig.Config{
265
-		Image: GetTestImage(daemon).ID,
266
-		Cmd:   []string{"/bin/true"},
267
-	}, "")
268
-	if err != nil {
269
-		t.Fatal(err)
270
-	}
271
-	defer daemon.Destroy(trueContainer)
272
-	if err := trueContainer.Run(); err != nil {
273
-		t.Fatal(err)
274
-	}
275
-	if code := trueContainer.State.GetExitCode(); code != 0 {
276
-		t.Fatalf("Unexpected exit code %d (expected 0)", code)
277
-	}
278
-
279
-	falseContainer, _, err := daemon.Create(&runconfig.Config{
280
-		Image: GetTestImage(daemon).ID,
281
-		Cmd:   []string{"/bin/false"},
282
-	}, "")
283
-	if err != nil {
284
-		t.Fatal(err)
285
-	}
286
-	defer daemon.Destroy(falseContainer)
287
-	if err := falseContainer.Run(); err != nil {
288
-		t.Fatal(err)
289
-	}
290
-	if code := falseContainer.State.GetExitCode(); code != 1 {
291
-		t.Fatalf("Unexpected exit code %d (expected 1)", code)
292
-	}
293
-}
294
-
295 182
 func TestRestart(t *testing.T) {
296 183
 	daemon := mkDaemon(t)
297 184
 	defer nuke(daemon)