From 116cdc6c7500a6773c7ba05a4c0e272a46c736ab Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Aug 2013 10:25:56 -0700 Subject: [PATCH] packer/rpc: ui.Machine works over RPC properly --- packer/rpc/ui.go | 12 ++++++------ packer/rpc/ui_test.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packer/rpc/ui.go b/packer/rpc/ui.go index 2a3807528..617541dde 100644 --- a/packer/rpc/ui.go +++ b/packer/rpc/ui.go @@ -19,8 +19,8 @@ type UiServer struct { // The arguments sent to Ui.Machine type UiMachineArgs struct { - category string - args []string + Category string + Args []string } func (u *Ui) Ask(query string) (result string, err error) { @@ -36,11 +36,11 @@ func (u *Ui) Error(message string) { func (u *Ui) Machine(t string, args ...string) { rpcArgs := &UiMachineArgs{ - category: t, - args: args, + Category: t, + Args: args, } - if err := u.client.Call("Ui.Message", rpcArgs, new(interface{})); err != nil { + if err := u.client.Call("Ui.Machine", rpcArgs, new(interface{})); err != nil { panic(err) } } @@ -70,7 +70,7 @@ func (u *UiServer) Error(message *string, reply *interface{}) error { } func (u *UiServer) Machine(args *UiMachineArgs, reply *interface{}) error { - u.ui.Machine(args.category, args.args...) + u.ui.Machine(args.Category, args.Args...) *reply = nil return nil diff --git a/packer/rpc/ui_test.go b/packer/rpc/ui_test.go index 7dae40763..dec0d4721 100644 --- a/packer/rpc/ui_test.go +++ b/packer/rpc/ui_test.go @@ -3,6 +3,7 @@ package rpc import ( "cgl.tideland.biz/asserts" "net/rpc" + "reflect" "testing" ) @@ -81,4 +82,18 @@ func TestUiRPC(t *testing.T) { uiClient.Say("message") assert.Equal(ui.sayMessage, "message", "message should be correct") + + uiClient.Machine("foo", "bar", "baz") + if !ui.machineCalled { + t.Fatal("machine should be called") + } + + if ui.machineType != "foo" { + t.Fatalf("bad type: %#v", ui.machineType) + } + + expected := []string{"bar", "baz"} + if !reflect.DeepEqual(ui.machineArgs, expected) { + t.Fatalf("bad: %#v", ui.machineArgs) + } }