diff --git a/commands_test.go b/commands_test.go index ebbe88c637..92343afad5 100644 --- a/commands_test.go +++ b/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()