packer/rpc: ui.Machine works over RPC properly

This commit is contained in:
Mitchell Hashimoto 2013-08-12 10:25:56 -07:00
parent 568f635824
commit 116cdc6c75
2 changed files with 21 additions and 6 deletions

View File

@ -19,8 +19,8 @@ type UiServer struct {
// The arguments sent to Ui.Machine // The arguments sent to Ui.Machine
type UiMachineArgs struct { type UiMachineArgs struct {
category string Category string
args []string Args []string
} }
func (u *Ui) Ask(query string) (result string, err error) { 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) { func (u *Ui) Machine(t string, args ...string) {
rpcArgs := &UiMachineArgs{ rpcArgs := &UiMachineArgs{
category: t, Category: t,
args: args, 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) panic(err)
} }
} }
@ -70,7 +70,7 @@ func (u *UiServer) Error(message *string, reply *interface{}) error {
} }
func (u *UiServer) Machine(args *UiMachineArgs, 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 *reply = nil
return nil return nil

View File

@ -3,6 +3,7 @@ package rpc
import ( import (
"cgl.tideland.biz/asserts" "cgl.tideland.biz/asserts"
"net/rpc" "net/rpc"
"reflect"
"testing" "testing"
) )
@ -81,4 +82,18 @@ func TestUiRPC(t *testing.T) {
uiClient.Say("message") uiClient.Say("message")
assert.Equal(ui.sayMessage, "message", "message should be correct") 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)
}
} }