2020-10-13 20:33:22 +02:00
|
|
|
package dotnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2021-03-17 14:20:05 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/internal/test"
|
2020-10-13 20:33:22 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGeneratePackage(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
schemaDir string
|
|
|
|
expectedFiles []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Simple schema with local resource properties",
|
|
|
|
"simple-resource-schema",
|
|
|
|
[]string{
|
|
|
|
"Resource.cs",
|
|
|
|
"OtherResource.cs",
|
|
|
|
"ArgFunction.cs",
|
|
|
|
},
|
|
|
|
},
|
2020-11-06 18:01:03 +01:00
|
|
|
{
|
|
|
|
"Simple schema with enum types",
|
|
|
|
"simple-enum-schema",
|
|
|
|
[]string{
|
|
|
|
"Tree/V1/RubberTree.cs",
|
2021-02-26 07:05:02 +01:00
|
|
|
"Tree/V1/Nursery.cs",
|
2020-11-06 18:01:03 +01:00
|
|
|
"Tree/V1/Enums.cs",
|
|
|
|
"Enums.cs",
|
|
|
|
"Inputs/ContainerArgs.cs",
|
|
|
|
"Outputs/Container.cs",
|
|
|
|
},
|
|
|
|
},
|
2020-11-20 21:09:34 +01:00
|
|
|
{
|
|
|
|
"External resource schema",
|
|
|
|
"external-resource-schema",
|
|
|
|
[]string{
|
|
|
|
"Inputs/PetArgs.cs",
|
|
|
|
"ArgFunction.cs",
|
|
|
|
"Cat.cs",
|
2020-11-23 21:28:00 +01:00
|
|
|
"Component.cs",
|
2020-11-20 21:09:34 +01:00
|
|
|
"Workload.cs",
|
|
|
|
},
|
|
|
|
},
|
2021-03-10 16:08:08 +01:00
|
|
|
{
|
|
|
|
"Simple schema with plain properties",
|
|
|
|
"simple-plain-schema",
|
|
|
|
[]string{
|
|
|
|
"Inputs/FooArgs.cs",
|
|
|
|
"Component.cs",
|
|
|
|
},
|
|
|
|
},
|
2020-10-13 20:33:22 +02:00
|
|
|
}
|
|
|
|
testDir := filepath.Join("..", "internal", "test", "testdata")
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
files, err := test.GeneratePackageFilesFromSchema(
|
|
|
|
filepath.Join(testDir, tt.schemaDir, "schema.json"), GeneratePackage)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
expectedFiles, err := test.LoadFiles(filepath.Join(testDir, tt.schemaDir), "dotnet", tt.expectedFiles)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
test.ValidateFileEquality(t, files, expectedFiles)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|