diff --git a/rpc/ui_output.go b/rpc/ui_output.go new file mode 100644 index 000000000..a997b943b --- /dev/null +++ b/rpc/ui_output.go @@ -0,0 +1,30 @@ +package rpc + +import ( + "net/rpc" + + "github.com/hashicorp/terraform/terraform" +) + +// UIOutput is an implementatin of terraform.UIOutput that communicates +// over RPC. +type UIOutput struct { + Client *rpc.Client + Name string +} + +func (o *UIOutput) Output(v string) { + o.Client.Call(o.Name+".Output", v, new(interface{})) +} + +// UIOutputServer is the RPC server for serving UIOutput. +type UIOutputServer struct { + UIOutput terraform.UIOutput +} + +func (s *UIOutputServer) Output( + v string, + reply *interface{}) error { + s.UIOutput.Output(v) + return nil +} diff --git a/rpc/ui_output_test.go b/rpc/ui_output_test.go new file mode 100644 index 000000000..0113a0903 --- /dev/null +++ b/rpc/ui_output_test.go @@ -0,0 +1,34 @@ +package rpc + +import ( + "testing" + + "github.com/hashicorp/terraform/terraform" +) + +func TestUIOutput_impl(t *testing.T) { + var _ terraform.UIOutput = new(UIOutput) +} + +func TestUIOutput_input(t *testing.T) { + client, server := testClientServer(t) + defer client.Close() + + o := new(terraform.MockUIOutput) + + err := server.RegisterName("UIOutput", &UIOutputServer{ + UIOutput: o, + }) + if err != nil { + t.Fatalf("err: %s", err) + } + + output := &UIOutput{Client: client, Name: "UIOutput"} + output.Output("foo") + if !o.OutputCalled { + t.Fatal("output should be called") + } + if o.OutputMessage != "foo" { + t.Fatalf("bad: %#v", o.OutputMessage) + } +} diff --git a/terraform/ui_output_mock.go b/terraform/ui_output_mock.go index 8e6ff82d7..8e16ac9af 100644 --- a/terraform/ui_output_mock.go +++ b/terraform/ui_output_mock.go @@ -10,7 +10,7 @@ type MockUIOutput struct { func (o *MockUIOutput) Output(v string) { o.OutputCalled = true o.OutputMessage= v - if o.OutputFn == nil { + if o.OutputFn != nil { o.OutputFn(v) } }