Explorar o código

Add unit test for container id format

Solomon Hykes %!s(int64=12) %!d(string=hai) anos
pai
achega
a8ae0aafe3
Modificáronse 1 ficheiros con 26 adicións e 0 borrados
  1. 26 0
      container_test.go

+ 26 - 0
container_test.go

@@ -7,12 +7,38 @@ import (
 	"io/ioutil"
 	"io/ioutil"
 	"math/rand"
 	"math/rand"
 	"os"
 	"os"
+	"regexp"
 	"sort"
 	"sort"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 	"time"
 	"time"
 )
 )
 
 
+func TestIdFormat(t *testing.T) {
+	runtime, err := newTestRuntime()
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer nuke(runtime)
+	container1, err := runtime.Create(
+		&Config{
+			Image:  GetTestImage(runtime).Id,
+			Cmd:    []string{"/bin/sh", "-c", "echo hello world"},
+			Memory: 33554432,
+		},
+	)
+	if err != nil {
+		t.Fatal(err)
+	}
+	match, err := regexp.Match("^[0-9a-f]{64}$", []byte(container1.Id))
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !match {
+		t.Fatalf("Invalid container ID: %s", container1.Id)
+	}
+}
+
 func TestCommitRun(t *testing.T) {
 func TestCommitRun(t *testing.T) {
 	runtime, err := newTestRuntime()
 	runtime, err := newTestRuntime()
 	if err != nil {
 	if err != nil {