Ejemplo n.º 1
0
func TestDoubleClient(t *testing.T) {
	assert := assrt.NewAssert(t)

	addr := siphon.NewAddr("test", "unix", "test.sock")

	cmd := exec.Command("cat", "-")
	host := siphon.NewHost(cmd, addr)
	host.Serve()
	defer host.UnServe()

	client1 := siphon.Connect(addr)

	client2 := siphon.Connect(addr)

	host.Start()

	go func() {
		// timed pauses are a hack required to make sure the host side flushes the echos in an order we can test.
		client1.Stdin().Write([]byte("foo\n"))
		time.Sleep(50 * time.Millisecond)
		client2.Stdin().Write([]byte("bar\n"))
		time.Sleep(50 * time.Millisecond)
		client1.Stdin().Write([]byte("baz\n"))
		time.Sleep(50 * time.Millisecond)
		client2.Stdin().Write([]byte{4}) // EOT
	}()

	outBuffer1 := new(bytes.Buffer)
	io.Copy(outBuffer1, client1.Stdout())
	out1 := string(outBuffer1.Bytes())

	outBuffer2 := new(bytes.Buffer)
	io.Copy(outBuffer2, client2.Stdout())
	out2 := string(outBuffer2.Bytes())

	expected :=
		"foo\r\nfoo\r\n" +
			"bar\r\nbar\r\n" +
			"baz\r\nbaz\r\n"
	assert.Equal(
		expected,
		out1,
	)
	assert.Equal(
		expected,
		out2,
	)
}
Ejemplo n.º 2
0
func (opts *attachOpts) Execute(args []string) error {
	addr, err := ParseNewAddr(opts.Address)
	if err != nil {
		fmt.Fprintf(os.Stderr, "siphon: %s\n", err)
		os.Exit(EXIT_BADARGS)
	}

	fmt.Printf("Attaching to %s\n", addr.Label)

	client := siphon.Connect(addr)

	client.Attach(os.Stdin, os.Stdout)

	return nil
}
Ejemplo n.º 3
0
func TestUnixSocket(t *testing.T) {
	assert := assrt.NewAssert(t)

	addr := siphon.NewAddr("test", "unix", "test.sock")

	cmd := exec.Command("cat", "-")
	host := siphon.NewHost(cmd, addr)
	host.Serve()
	defer host.UnServe()

	client := siphon.Connect(addr)
	//client.Attach() // you can't do this in a test.  there's no tty.

	//FIXME: there's really no guarantee that the host finished processing the client connect request by now
	host.Start()

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

	outBuffer := new(bytes.Buffer)
	io.Copy(outBuffer, client.Stdout())
	out := string(outBuffer.Bytes())

	expected :=
		"foo\r\n" +
			"bar\r\n" +
			"baz\r\n"
	expected = expected + expected
	assert.Equal(
		expected,
		out,
	)
}