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