pulumi/pkg/codegen/dotnet/gen_test.go
Pat Gavlin d07b325138
[codegen] Add type name generation tests. (#7470)
The inputs and expected outputs for the tests are encoded using a
schema. Each property present in the schema forms a testcase; the
expected outputs for each language are stored in each property's
`Language` field with the language name "test". Expected outputs can be
regenerated using `PULUMI_ACCEPT`.
2021-07-09 10:23:10 -07:00

73 lines
1.6 KiB
Go

package dotnet
import (
"testing"
"github.com/pulumi/pulumi/pkg/v3/codegen/internal/test"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGeneratePackage(t *testing.T) {
test.TestSDKCodegen(t, "dotnet", GeneratePackage)
}
func TestGenerateType(t *testing.T) {
cases := []struct {
typ schema.Type
expected string
}{
{
&schema.InputType{
ElementType: &schema.ArrayType{
ElementType: &schema.InputType{
ElementType: &schema.ArrayType{
ElementType: &schema.InputType{
ElementType: schema.NumberType,
},
},
},
},
},
"InputList<ImmutableArray<double>>",
},
{
&schema.InputType{
ElementType: &schema.MapType{
ElementType: &schema.InputType{
ElementType: &schema.ArrayType{
ElementType: &schema.InputType{
ElementType: schema.NumberType,
},
},
},
},
},
"InputMap<ImmutableArray<double>>",
},
}
mod := &modContext{mod: "main"}
for _, c := range cases {
t.Run(c.typ.String(), func(t *testing.T) {
typeString := mod.typeString(c.typ, "", true, false, false)
assert.Equal(t, c.expected, typeString)
})
}
}
func TestGenerateTypeNames(t *testing.T) {
test.TestTypeNameCodegen(t, "dotnet", func(pkg *schema.Package) test.TypeNameGeneratorFunc {
modules, _, err := generateModuleContextMap("test", pkg)
require.NoError(t, err)
root, ok := modules[""]
require.True(t, ok)
return func(t schema.Type) string {
return root.typeString(t, "", false, false, false)
}
})
}