rpc: UIOutput
This commit is contained in:
parent
6445e1f16a
commit
509f293bea
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue