コード例 #1
0
ファイル: siphon_test.go プロジェクト: nk23x/siphon-cli
func TestGrep(t *testing.T) {
	assert := assrt.NewAssert(t)

	cmd := exec.Command("grep", "--color=auto", "bar")
	host := siphon.NewHost(cmd, siphon.NewInternalAddr())
	host.Start()

	go func() {
		stdin := host.StdinPipe()
		stdin.Write([]byte("foo\nbar\nbaz\n"))
		stdin.Write([]byte{4}) // EOT
	}()

	outBuffer := new(bytes.Buffer)
	io.Copy(outBuffer, host.StdoutPipe())
	out := string(outBuffer.Bytes())

	expected := // I have no idea where the CR characters come from.
		"foo\r\n" +
			"bar\r\n" +
			"baz\r\n" +
			"bar\r\n"

	assert.Equal(
		expected,
		out,
	)
}
コード例 #2
0
ファイル: siphon_test.go プロジェクト: nk23x/siphon-cli
/**
Getting any answer from the tty command at all is pretty good news, since `go test` doesn't let the shell's tty come through.
*/
func TestActuallyNewTty(t *testing.T) {
	assert := assrt.NewAssert(t)

	cmd := exec.Command("tty")
	host := siphon.NewHost(cmd, siphon.NewInternalAddr())
	outBuffer := new(bytes.Buffer)
	hostOut := host.StdoutPipe()
	host.Start()
	io.Copy(outBuffer, hostOut)

	innerTty := string(outBuffer.Bytes())

	assert.NotEqual(
		"", // what exactly you get varies on the current state of your machine, but something like /dev/pts/12 is reasonable.
		innerTty,
	)
}