github.com/cycloidio/terraform@v1.1.10-0.20220513142504-76d5c768dc63/plugin/ui_input_test.go (about)

     1  package plugin
     2  
     3  import (
     4  	"context"
     5  	"reflect"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/go-plugin"
     9  	"github.com/cycloidio/terraform/terraform"
    10  )
    11  
    12  func TestUIInput_impl(t *testing.T) {
    13  	var _ terraform.UIInput = new(UIInput)
    14  }
    15  
    16  func TestUIInput_input(t *testing.T) {
    17  	client, server := plugin.TestRPCConn(t)
    18  	defer client.Close()
    19  
    20  	i := new(terraform.MockUIInput)
    21  	i.InputReturnString = "foo"
    22  
    23  	err := server.RegisterName("Plugin", &UIInputServer{
    24  		UIInput: i,
    25  	})
    26  	if err != nil {
    27  		t.Fatalf("err: %s", err)
    28  	}
    29  
    30  	input := &UIInput{Client: client}
    31  
    32  	opts := &terraform.InputOpts{
    33  		Id: "foo",
    34  	}
    35  
    36  	v, err := input.Input(context.Background(), opts)
    37  	if !i.InputCalled {
    38  		t.Fatal("input should be called")
    39  	}
    40  	if !reflect.DeepEqual(i.InputOpts, opts) {
    41  		t.Fatalf("bad: %#v", i.InputOpts)
    42  	}
    43  	if err != nil {
    44  		t.Fatalf("bad: %#v", err)
    45  	}
    46  
    47  	if v != "foo" {
    48  		t.Fatalf("bad: %#v", v)
    49  	}
    50  }