mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-23 03:34:30 -05:00
* Add metadata functions command skeleton * Export functions as JSON via cli command * Add metadata command * Add tests to jsonfunction package * WIP: Add metadata functions test * Change return_type & type in JSON to json.RawMessage This enables easier deserialisation of types when parsing the JSON. * Skip is_nullable when false * Update cli docs with metadata command * Use tfdiags to report function marshal errors * Ignore map, list and type functions * Test Marshal function with diags * Test metadata functions command output * Simplify type marshaling by using cty.Type * Add static function signatures for can and try * Update internal/command/jsonfunction/function_test.go Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> --------- Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package jsonfunction
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/zclconf/go-cty-debug/ctydebug"
|
|
"github.com/zclconf/go-cty/cty"
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
)
|
|
|
|
func TestMarshalParameter(t *testing.T) {
|
|
tests := []struct {
|
|
Name string
|
|
Input *function.Parameter
|
|
Want *parameter
|
|
}{
|
|
{
|
|
"call with nil",
|
|
nil,
|
|
¶meter{},
|
|
},
|
|
{
|
|
"parameter with description",
|
|
&function.Parameter{
|
|
Name: "timestamp",
|
|
Description: "`timestamp` returns a UTC timestamp string in [RFC 3339]",
|
|
Type: cty.String,
|
|
},
|
|
¶meter{
|
|
Name: "timestamp",
|
|
Description: "`timestamp` returns a UTC timestamp string in [RFC 3339]",
|
|
Type: cty.String,
|
|
},
|
|
},
|
|
{
|
|
"parameter with additional properties",
|
|
&function.Parameter{
|
|
Name: "value",
|
|
Type: cty.DynamicPseudoType,
|
|
AllowUnknown: true,
|
|
AllowNull: true,
|
|
AllowMarked: true,
|
|
AllowDynamicType: true,
|
|
},
|
|
¶meter{
|
|
Name: "value",
|
|
Type: cty.DynamicPseudoType,
|
|
IsNullable: true,
|
|
},
|
|
},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
t.Run(fmt.Sprintf("%d-%s", i, test.Name), func(t *testing.T) {
|
|
got := marshalParameter(test.Input)
|
|
|
|
if diff := cmp.Diff(test.Want, got, ctydebug.CmpOptions); diff != "" {
|
|
t.Fatalf("mismatch of parameter signature: %s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|