github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonfunction/parameter_test.go (about)

     1  package jsonfunction
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/zclconf/go-cty-debug/ctydebug"
     9  	"github.com/zclconf/go-cty/cty"
    10  	"github.com/zclconf/go-cty/cty/function"
    11  )
    12  
    13  func TestMarshalParameter(t *testing.T) {
    14  	tests := []struct {
    15  		Name  string
    16  		Input *function.Parameter
    17  		Want  *parameter
    18  	}{
    19  		{
    20  			"call with nil",
    21  			nil,
    22  			&parameter{},
    23  		},
    24  		{
    25  			"parameter with description",
    26  			&function.Parameter{
    27  				Name:        "timestamp",
    28  				Description: "`timestamp` returns a UTC timestamp string in [RFC 3339]",
    29  				Type:        cty.String,
    30  			},
    31  			&parameter{
    32  				Name:        "timestamp",
    33  				Description: "`timestamp` returns a UTC timestamp string in [RFC 3339]",
    34  				Type:        cty.String,
    35  			},
    36  		},
    37  		{
    38  			"parameter with additional properties",
    39  			&function.Parameter{
    40  				Name:             "value",
    41  				Type:             cty.DynamicPseudoType,
    42  				AllowUnknown:     true,
    43  				AllowNull:        true,
    44  				AllowMarked:      true,
    45  				AllowDynamicType: true,
    46  			},
    47  			&parameter{
    48  				Name:       "value",
    49  				Type:       cty.DynamicPseudoType,
    50  				IsNullable: true,
    51  			},
    52  		},
    53  	}
    54  
    55  	for i, test := range tests {
    56  		t.Run(fmt.Sprintf("%d-%s", i, test.Name), func(t *testing.T) {
    57  			got := marshalParameter(test.Input)
    58  
    59  			if diff := cmp.Diff(test.Want, got, ctydebug.CmpOptions); diff != "" {
    60  				t.Fatalf("mismatch of parameter signature: %s", diff)
    61  			}
    62  		})
    63  	}
    64  }