Browse code

Add unit test for container id format

Solomon Hykes authored on 2013/03/27 08:54:13
Showing 1 changed files
... ...
@@ -7,12 +7,38 @@ import (
7 7
 	"io/ioutil"
8 8
 	"math/rand"
9 9
 	"os"
10
+	"regexp"
10 11
 	"sort"
11 12
 	"strings"
12 13
 	"testing"
13 14
 	"time"
14 15
 )
15 16
 
17
+func TestIdFormat(t *testing.T) {
18
+	runtime, err := newTestRuntime()
19
+	if err != nil {
20
+		t.Fatal(err)
21
+	}
22
+	defer nuke(runtime)
23
+	container1, err := runtime.Create(
24
+		&Config{
25
+			Image:  GetTestImage(runtime).Id,
26
+			Cmd:    []string{"/bin/sh", "-c", "echo hello world"},
27
+			Memory: 33554432,
28
+		},
29
+	)
30
+	if err != nil {
31
+		t.Fatal(err)
32
+	}
33
+	match, err := regexp.Match("^[0-9a-f]{64}$", []byte(container1.Id))
34
+	if err != nil {
35
+		t.Fatal(err)
36
+	}
37
+	if !match {
38
+		t.Fatalf("Invalid container ID: %s", container1.Id)
39
+	}
40
+}
41
+
16 42
 func TestCommitRun(t *testing.T) {
17 43
 	runtime, err := newTestRuntime()
18 44
 	if err != nil {