opentofu/internal/plugin/ui_input_test.go

56 lines
1,018 B
Go
Raw Permalink Normal View History

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package plugin
2014-09-29 03:23:17 -04:00
import (
"context"
2014-09-29 03:23:17 -04:00
"reflect"
"testing"
"github.com/hashicorp/go-plugin"
2023-09-20 08:16:53 -04:00
"github.com/opentofu/opentofu/internal/tofu"
2014-09-29 03:23:17 -04:00
)
func TestUIInput_impl(t *testing.T) {
2023-09-20 08:16:53 -04:00
var _ tofu.UIInput = new(UIInput)
2014-09-29 03:23:17 -04:00
}
func TestUIInput_input(t *testing.T) {
client, server := plugin.TestRPCConn(t)
2014-09-29 03:23:17 -04:00
defer client.Close()
2023-09-20 08:16:53 -04:00
i := new(tofu.MockUIInput)
2014-09-29 03:23:17 -04:00
i.InputReturnString = "foo"
err := server.RegisterName("Plugin", &UIInputServer{
2014-09-29 03:23:17 -04:00
UIInput: i,
})
if err != nil {
t.Fatalf("err: %s", err)
}
input := &UIInput{Client: client}
2014-09-29 03:23:17 -04:00
2023-09-20 08:16:53 -04:00
opts := &tofu.InputOpts{
2014-09-29 03:23:17 -04:00
Id: "foo",
}
v, err := input.Input(context.Background(), opts)
2014-09-29 03:23:17 -04: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)
}
}