Browse code

Add test verify container ID Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/04/18 10:58:20
Showing 2 changed files
... ...
@@ -3,6 +3,7 @@ package main
3 3
 import (
4 4
 	"fmt"
5 5
 	"os/exec"
6
+	"regexp"
6 7
 	"strings"
7 8
 	"testing"
8 9
 )
... ...
@@ -384,3 +385,26 @@ func TestMultipleVolumesFrom(t *testing.T) {
384 384
 
385 385
 	logDone("run - multiple volumes from")
386 386
 }
387
+
388
+// this tests verifies the ID format for the container
389
+func TestVerifyContainerID(t *testing.T) {
390
+	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
391
+	out, exit, err := runCommandWithOutput(cmd)
392
+	if err != nil {
393
+		t.Fatal(err)
394
+	}
395
+	if exit != 0 {
396
+		t.Fatalf("expected exit code 0 received %d", exit)
397
+	}
398
+	match, err := regexp.MatchString("^[0-9a-f]{64}$", strings.TrimSuffix(out, "\n"))
399
+	if err != nil {
400
+		t.Fatal(err)
401
+	}
402
+	if !match {
403
+		t.Fatalf("Invalid container ID: %s", out)
404
+	}
405
+
406
+	deleteAllContainers()
407
+
408
+	logDone("run - verify container ID")
409
+}
... ...
@@ -16,28 +16,6 @@ import (
16 16
 	"time"
17 17
 )
18 18
 
19
-func TestIDFormat(t *testing.T) {
20
-	daemon := mkDaemon(t)
21
-	defer nuke(daemon)
22
-	container1, _, err := daemon.Create(
23
-		&runconfig.Config{
24
-			Image: GetTestImage(daemon).ID,
25
-			Cmd:   []string{"/bin/sh", "-c", "echo hello world"},
26
-		},
27
-		"",
28
-	)
29
-	if err != nil {
30
-		t.Fatal(err)
31
-	}
32
-	match, err := regexp.Match("^[0-9a-f]{64}$", []byte(container1.ID))
33
-	if err != nil {
34
-		t.Fatal(err)
35
-	}
36
-	if !match {
37
-		t.Fatalf("Invalid container ID: %s", container1.ID)
38
-	}
39
-}
40
-
41 19
 func TestMultipleAttachRestart(t *testing.T) {
42 20
 	daemon := mkDaemon(t)
43 21
 	defer nuke(daemon)