2014-11-20 00:19:16 -05:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"unicode"
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-11-20 00:19:16 -05:00
|
|
|
"github.com/kr/pty"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #5979
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestEventsRedirectStdout(c *check.C) {
|
|
|
|
since := daemonTime(c).Unix()
|
|
|
|
dockerCmd(c, "run", "busybox", "true")
|
2014-11-20 00:19:16 -05:00
|
|
|
|
|
|
|
file, err := ioutil.TempFile("", "")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("could not create temp file: %v", err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
command := fmt.Sprintf("%s events --since=%d --until=%d > %s", dockerBinary, since, daemonTime(c).Unix(), file.Name())
|
2014-11-20 00:19:16 -05:00
|
|
|
_, tty, err := pty.Open()
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not open pty: %v", err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
cmd := exec.Command("sh", "-c", command)
|
|
|
|
cmd.Stdin = tty
|
|
|
|
cmd.Stdout = tty
|
|
|
|
cmd.Stderr = tty
|
|
|
|
if err := cmd.Run(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("run err for command %q: %v", command, err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
2015-04-18 12:46:47 -04:00
|
|
|
for _, ch := range scanner.Text() {
|
|
|
|
if unicode.IsControl(ch) {
|
|
|
|
c.Fatalf("found control character %v", []byte(string(ch)))
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Scan err for command %q: %v", command, err)
|
2014-11-20 00:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|