packer/rpc: implement UploadDir
This commit is contained in:
parent
8b21b5b713
commit
1010c8ae19
|
@ -20,6 +20,10 @@ type MockCommunicator struct {
|
|||
UploadPath string
|
||||
UploadData string
|
||||
|
||||
UploadDirDst string
|
||||
UploadDirSrc string
|
||||
UploadDirExclude []string
|
||||
|
||||
DownloadCalled bool
|
||||
DownloadPath string
|
||||
DownloadData string
|
||||
|
@ -78,7 +82,11 @@ func (c *MockCommunicator) Upload(path string, r io.Reader) error {
|
|||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,12 @@ type CommunicatorUploadArgs struct {
|
|||
ReaderAddress string
|
||||
}
|
||||
|
||||
type CommunicatorUploadDirArgs struct {
|
||||
Dst string
|
||||
Src string
|
||||
Exclude []string
|
||||
}
|
||||
|
||||
func Communicator(client *rpc.Client) *communicator {
|
||||
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 {
|
||||
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) {
|
||||
|
@ -227,6 +245,10 @@ func (c *CommunicatorServer) Upload(args *CommunicatorUploadArgs, reply *interfa
|
|||
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) {
|
||||
writerC, err := net.Dial("tcp", args.WriterAddress)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/mitchellh/packer/packer"
|
||||
"io"
|
||||
"net/rpc"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -104,6 +105,27 @@ func TestCommunicatorRPC(t *testing.T) {
|
|||
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
|
||||
downloadR, downloadW := io.Pipe()
|
||||
downloadDone := make(chan bool)
|
||||
|
|
Loading…
Reference in New Issue