10
"github.com/lxc/lxd/shared"
13
const helloWorld = "hello world\n"
15
func TestRsyncSendRecv(t *testing.T) {
16
source, err := ioutil.TempDir("", "lxd_test_source_")
21
defer os.RemoveAll(source)
23
sink, err := ioutil.TempDir("", "lxd_test_sink_")
28
defer os.RemoveAll(sink)
30
/* now, write something to rsync over */
31
f, err := os.Create(path.Join(source, "foo"))
36
f.Write([]byte(helloWorld))
39
send, sendConn, _, err := rsyncSendSetup(shared.AddSlash(source))
45
recv := rsyncRecvCmd(sink)
47
recvOut, err := recv.StdoutPipe()
53
recvIn, err := recv.StdinPipe()
59
if err := recv.Start(); err != nil {
65
defer sendConn.Close()
66
if _, err := io.Copy(sendConn, recvOut); err != nil {
70
if err := recv.Wait(); err != nil {
77
* We close the socket in the above gofunc, but go tells us
78
* https://github.com/golang/go/issues/4373 that this is an error
79
* because we were reading from a socket that was closed. Thus, we
82
io.Copy(recvIn, sendConn)
84
if err := send.Wait(); err != nil {
89
f, err = os.Open(path.Join(sink, "foo"))
96
buf, err := ioutil.ReadAll(f)
102
if string(buf) != helloWorld {
103
t.Errorf("expected %s got %s", helloWorld, buf)