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 { ...@@ -46,10 +46,18 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
RegisterHook(server, hook) RegisterHook(server, hook)
args := &BuilderRunArgs{serveSingleConn(server)} args := &BuilderRunArgs{serveSingleConn(server)}
b.client.Call("Builder.Run", args, new(interface{}))
// TODO: artifact var reply string
return nil 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 { func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
...@@ -61,7 +69,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error { ...@@ -61,7 +69,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *error) error {
return nil 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) client, err := rpc.Dial("tcp", args.RPCAddress)
if err != nil { if err != nil {
return err return err
...@@ -69,8 +77,12 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error { ...@@ -69,8 +77,12 @@ func (b *BuilderServer) Run(args *BuilderRunArgs, reply *interface{}) error {
hook := Hook(client) hook := Hook(client)
ui := &Ui{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 return nil
} }
...@@ -7,6 +7,8 @@ import ( ...@@ -7,6 +7,8 @@ import (
"testing" "testing"
) )
var testBuilderArtifact = &testArtifact{}
type testBuilder struct { type testBuilder struct {
prepareCalled bool prepareCalled bool
prepareConfig interface{} prepareConfig interface{}
...@@ -25,7 +27,7 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact { ...@@ -25,7 +27,7 @@ func (b *testBuilder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact {
b.runCalled = true b.runCalled = true
b.runHook = hook b.runHook = hook
b.runUi = ui b.runUi = ui
return nil return testBuilderArtifact
} }
func TestBuilderRPC(t *testing.T) { func TestBuilderRPC(t *testing.T) {
...@@ -53,7 +55,7 @@ func TestBuilderRPC(t *testing.T) { ...@@ -53,7 +55,7 @@ func TestBuilderRPC(t *testing.T) {
// Test Run // Test Run
hook := &testHook{} hook := &testHook{}
ui := &testUi{} ui := &testUi{}
bClient.Run(ui, hook) artifact := bClient.Run(ui, hook)
assert.True(b.runCalled, "runs hould be called") assert.True(b.runCalled, "runs hould be called")
if b.runCalled { if b.runCalled {
...@@ -63,6 +65,8 @@ func TestBuilderRPC(t *testing.T) { ...@@ -63,6 +65,8 @@ func TestBuilderRPC(t *testing.T) {
b.runUi.Say("format") b.runUi.Say("format")
assert.True(ui.sayCalled, "say should be called") assert.True(ui.sayCalled, "say should be called")
assert.Equal(ui.sayFormat, "format", "format should be correct") 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