terraform/internal/plugin/ui_input_test.go

51 lines
891 B
Go
Raw Permalink Normal View History

package plugin
2014-09-29 09:23:17 +02:00
import (
"context"
2014-09-29 09:23:17 +02:00
"reflect"
"testing"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/terraform/internal/terraform"
2014-09-29 09:23:17 +02:00
)
func TestUIInput_impl(t *testing.T) {
var _ terraform.UIInput = new(UIInput)
}
func TestUIInput_input(t *testing.T) {
client, server := plugin.TestRPCConn(t)
2014-09-29 09:23:17 +02:00
defer client.Close()
i := new(terraform.MockUIInput)
i.InputReturnString = "foo"
err := server.RegisterName("Plugin", &UIInputServer{
2014-09-29 09:23:17 +02:00
UIInput: i,
})
if err != nil {
t.Fatalf("err: %s", err)
}
input := &UIInput{Client: client}
2014-09-29 09:23:17 +02:00
opts := &terraform.InputOpts{
Id: "foo",
}
v, err := input.Input(context.Background(), opts)
2014-09-29 09:23:17 +02:00
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)
}
}