浏览代码

TestRunHostname checks that 'docker run -h' correctly sets a custom hostname

Solomon Hykes 12 年之前
父节点
当前提交
b1fa26bb76
共有 1 个文件被更改,包括 23 次插入0 次删除
  1. 23 0
      commands_test.go

+ 23 - 0
commands_test.go

@@ -2,8 +2,10 @@ package docker
 
 import (
 	"bufio"
+	"bytes"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"strings"
 	"testing"
 	"time"
@@ -57,6 +59,27 @@ func assertPipe(input, output string, r io.Reader, w io.Writer, count int) error
 	return nil
 }
 
+// TestRunHostname checks that 'docker run -h' correctly sets a custom hostname
+func TestRunHostname(t *testing.T) {
+	runtime, err := newTestRuntime()
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer nuke(runtime)
+
+	srv := &Server{runtime: runtime}
+
+	var stdin, stdout bytes.Buffer
+	setTimeout(t, "CmdRun timed out", 2*time.Second, func() {
+		if err := srv.CmdRun(ioutil.NopCloser(&stdin), &nopWriteCloser{&stdout}, "-h", "foobar", GetTestImage(runtime).Id, "hostname"); err != nil {
+			t.Fatal(err)
+		}
+	})
+	if output := string(stdout.Bytes()); output != "foobar\n" {
+		t.Fatalf("'hostname' should display '%s', not '%s'", "foobar\n", output)
+	}
+}
+
 // Expected behaviour: the process dies when the client disconnects
 func TestRunDisconnect(t *testing.T) {
 	runtime, err := newTestRuntime()