2016-01-25 03:10:52 +01:00
|
|
|
package plugin
|
2014-09-29 09:23:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-25 03:10:52 +01:00
|
|
|
"github.com/hashicorp/go-plugin"
|
2014-09-29 09:23:17 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUIInput_impl(t *testing.T) {
|
|
|
|
var _ terraform.UIInput = new(UIInput)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUIInput_input(t *testing.T) {
|
2016-01-25 03:10:52 +01:00
|
|
|
client, server := plugin.TestRPCConn(t)
|
2014-09-29 09:23:17 +02:00
|
|
|
defer client.Close()
|
|
|
|
|
|
|
|
i := new(terraform.MockUIInput)
|
|
|
|
i.InputReturnString = "foo"
|
|
|
|
|
2016-01-25 03:10:52 +01:00
|
|
|
err := server.RegisterName("Plugin", &UIInputServer{
|
2014-09-29 09:23:17 +02:00
|
|
|
UIInput: i,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-01-25 03:10:52 +01:00
|
|
|
input := &UIInput{Client: client}
|
2014-09-29 09:23:17 +02:00
|
|
|
|
|
|
|
opts := &terraform.InputOpts{
|
|
|
|
Id: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err := input.Input(opts)
|
|
|
|
if !i.InputCalled {
|
|
|
|
t.Fatal("input should be called")
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(i.InputOpts, opts) {
|
|
|
|
t.Fatalf("bad: %#v", i.InputOpts)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if v != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
|
|
|
}
|