Browse code

Tests on container state changing

It could catch error that was fixed in #6954
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)

Alexandr Morozov authored on 2014/07/17 15:15:23
Showing 1 changed files
... ...
@@ -1295,3 +1295,69 @@ func TestAttachStdOutAndErrTTYMode(t *testing.T) {
1295 1295
 
1296 1296
 	logDone("run - Attach stderr and stdout with -t")
1297 1297
 }
1298
+
1299
+func TestState(t *testing.T) {
1300
+	defer deleteAllContainers()
1301
+	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
1302
+
1303
+	out, _, err := runCommandWithOutput(cmd)
1304
+	if err != nil {
1305
+		t.Fatal(err, out)
1306
+	}
1307
+	id := strings.TrimSpace(out)
1308
+	state, err := inspectField(id, "State.Running")
1309
+	if err != nil {
1310
+		t.Fatal(err)
1311
+	}
1312
+	if state != "true" {
1313
+		t.Fatal("Container state is 'not running'")
1314
+	}
1315
+	pid1, err := inspectField(id, "State.Pid")
1316
+	if err != nil {
1317
+		t.Fatal(err)
1318
+	}
1319
+	if pid1 == "0" {
1320
+		t.Fatal("Container state Pid 0")
1321
+	}
1322
+
1323
+	cmd = exec.Command(dockerBinary, "stop", id)
1324
+	out, _, err = runCommandWithOutput(cmd)
1325
+	if err != nil {
1326
+		t.Fatal(err, out)
1327
+	}
1328
+	state, err = inspectField(id, "State.Running")
1329
+	if err != nil {
1330
+		t.Fatal(err)
1331
+	}
1332
+	if state != "false" {
1333
+		t.Fatal("Container state is 'running'")
1334
+	}
1335
+	pid2, err := inspectField(id, "State.Pid")
1336
+	if err != nil {
1337
+		t.Fatal(err)
1338
+	}
1339
+	if pid2 == pid1 {
1340
+		t.Fatalf("Container state Pid %s, but expected %s", pid2, pid1)
1341
+	}
1342
+
1343
+	cmd = exec.Command(dockerBinary, "start", id)
1344
+	out, _, err = runCommandWithOutput(cmd)
1345
+	if err != nil {
1346
+		t.Fatal(err, out)
1347
+	}
1348
+	state, err = inspectField(id, "State.Running")
1349
+	if err != nil {
1350
+		t.Fatal(err)
1351
+	}
1352
+	if state != "true" {
1353
+		t.Fatal("Container state is 'not running'")
1354
+	}
1355
+	pid3, err := inspectField(id, "State.Pid")
1356
+	if err != nil {
1357
+		t.Fatal(err)
1358
+	}
1359
+	if pid3 == pid1 {
1360
+		t.Fatalf("Container state Pid %s, but expected %s", pid2, pid1)
1361
+	}
1362
+	logDone("run - test container state.")
1363
+}