github.com/opentofu/opentofu@v1.7.1/internal/plugin/ui_output_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  	"testing"
    10  
    11  	"github.com/hashicorp/go-plugin"
    12  	"github.com/opentofu/opentofu/internal/tofu"
    13  )
    14  
    15  func TestUIOutput_impl(t *testing.T) {
    16  	var _ tofu.UIOutput = new(UIOutput)
    17  }
    18  
    19  func TestUIOutput_input(t *testing.T) {
    20  	client, server := plugin.TestRPCConn(t)
    21  	defer client.Close()
    22  
    23  	o := new(tofu.MockUIOutput)
    24  
    25  	err := server.RegisterName("Plugin", &UIOutputServer{
    26  		UIOutput: o,
    27  	})
    28  	if err != nil {
    29  		t.Fatalf("err: %s", err)
    30  	}
    31  
    32  	output := &UIOutput{Client: client}
    33  	output.Output("foo")
    34  	if !o.OutputCalled {
    35  		t.Fatal("output should be called")
    36  	}
    37  	if o.OutputMessage != "foo" {
    38  		t.Fatalf("bad: %#v", o.OutputMessage)
    39  	}
    40  }