packer/rpc: implement UploadDir
This commit is contained in:
parent
dbfe8e21e1
commit
8a194a3750
|
@ -20,6 +20,10 @@ type MockCommunicator struct {
|
||||||
UploadPath string
|
UploadPath string
|
||||||
UploadData string
|
UploadData string
|
||||||
|
|
||||||
|
UploadDirDst string
|
||||||
|
UploadDirSrc string
|
||||||
|
UploadDirExclude []string
|
||||||
|
|
||||||
DownloadCalled bool
|
DownloadCalled bool
|
||||||
DownloadPath string
|
DownloadPath string
|
||||||
DownloadData string
|
DownloadData string
|
||||||
|
@ -78,7 +82,11 @@ func (c *MockCommunicator) Upload(path string, r io.Reader) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockCommunicator) UploadDir(string, string, []string) error {
|
func (c *MockCommunicator) UploadDir(dst string, src string, excl []string) error {
|
||||||
|
c.UploadDirDst = dst
|
||||||
|
c.UploadDirSrc = src
|
||||||
|
c.UploadDirExclude = excl
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,12 @@ type CommunicatorUploadArgs struct {
|
||||||
ReaderAddress string
|
ReaderAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommunicatorUploadDirArgs struct {
|
||||||
|
Dst string
|
||||||
|
Src string
|
||||||
|
Exclude []string
|
||||||
|
}
|
||||||
|
|
||||||
func Communicator(client *rpc.Client) *communicator {
|
func Communicator(client *rpc.Client) *communicator {
|
||||||
return &communicator{client}
|
return &communicator{client}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +130,19 @@ func (c *communicator) Upload(path string, r io.Reader) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *communicator) UploadDir(dst string, src string, exclude []string) error {
|
func (c *communicator) UploadDir(dst string, src string, exclude []string) error {
|
||||||
return nil
|
args := &CommunicatorUploadDirArgs{
|
||||||
|
Dst: dst,
|
||||||
|
Src: src,
|
||||||
|
Exclude: exclude,
|
||||||
|
}
|
||||||
|
|
||||||
|
var reply error
|
||||||
|
err := c.client.Call("Communicator.UploadDir", args, &reply)
|
||||||
|
if err == nil {
|
||||||
|
err = reply
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *communicator) Download(path string, w io.Writer) (err error) {
|
func (c *communicator) Download(path string, w io.Writer) (err error) {
|
||||||
|
@ -227,6 +245,10 @@ func (c *CommunicatorServer) Upload(args *CommunicatorUploadArgs, reply *interfa
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CommunicatorServer) UploadDir(args *CommunicatorUploadDirArgs, reply *error) error {
|
||||||
|
return c.c.UploadDir(args.Dst, args.Src, args.Exclude)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *interface{}) (err error) {
|
func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *interface{}) (err error) {
|
||||||
writerC, err := net.Dial("tcp", args.WriterAddress)
|
writerC, err := net.Dial("tcp", args.WriterAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"io"
|
"io"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -104,6 +105,27 @@ func TestCommunicatorRPC(t *testing.T) {
|
||||||
t.Fatalf("bad: %s", c.UploadData)
|
t.Fatalf("bad: %s", c.UploadData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that we can upload directories
|
||||||
|
dirDst := "foo"
|
||||||
|
dirSrc := "bar"
|
||||||
|
dirExcl := []string{"foo"}
|
||||||
|
err = remote.UploadDir(dirDst, dirSrc, dirExcl)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.UploadDirDst != dirDst {
|
||||||
|
t.Fatalf("bad: %s", c.UploadDirDst)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.UploadDirSrc != dirSrc {
|
||||||
|
t.Fatalf("bad: %s", c.UploadDirSrc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(c.UploadDirExclude, dirExcl) {
|
||||||
|
t.Fatalf("bad: %#v", c.UploadDirExclude)
|
||||||
|
}
|
||||||
|
|
||||||
// Test that we can download things
|
// Test that we can download things
|
||||||
downloadR, downloadW := io.Pipe()
|
downloadR, downloadW := io.Pipe()
|
||||||
downloadDone := make(chan bool)
|
downloadDone := make(chan bool)
|
||||||
|
|
Loading…
Reference in New Issue