Commit caa2b771 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: Builders return valid artifacts

parent 53c3d330
......@@ -46,10 +46,18 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
RegisterHook(server, hook)
args := &BuilderRunArgs{serveSingleConn(server)}
b.client.Call("Builder.Run", args, new(interface{}))
// TODO: artifact
return nil
var reply string
if err := b.client.Call("Builder.Run", args, &reply); err != nil {
panic(err)
}
client, err := rpc.Dial("tcp", reply)
if err != nil {
panic(err)
}
return Artifact(client)
}
func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
......@@ -61,7 +69,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
return nil
}
func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
func (b *BuilderServer) Run(args *BuilderRunArgs, reply *string) error {
client, err := rpc.Dial("tcp", args.RPCAddress)
if err != nil {
return err
......@@ -69,8 +77,12 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
hook := Hook(client)
ui := &Ui{client}
b.builder.Run(ui, hook)
artifact := b.builder.Run(ui, hook)
// Wrap the artifact
server := rpc.NewServer()
RegisterArtifact(server, artifact)
*reply = nil
*reply = serveSingleConn(server)
return nil
}
......@@ -7,6 +7,8 @@ import (
"testing"
)
var testBuilderArtifact = &testArtifact{}
type testBuilder struct {
prepareCalled bool
prepareConfig interface{}
......@@ -25,7 +27,7 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
b.runCalled = true
b.runHook = hook
b.runUi = ui
return nil
return testBuilderArtifact
}
func TestBuilderRPC(t *testing.T) {
......@@ -53,7 +55,7 @@ func TestBuilderRPC(t *testing.T) {
// Test Run
hook := &testHook{}
ui := &testUi{}
bClient.Run(ui, hook)
artifact := bClient.Run(ui, hook)
assert.True(b.runCalled, "runs hould be called")
if b.runCalled {
......@@ -63,6 +65,8 @@ func TestBuilderRPC(t *testing.T) {
b.runUi.Say("format")
assert.True(ui.sayCalled, "say should be called")
assert.Equal(ui.sayFormat, "format", "format should be correct")
assert.Equal(artifact.Id(), testBuilderArtifact.Id(), "should have artifact Id")
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment