2020-10-08 03:13:10 +02:00
|
|
|
// nolint: lll
|
2020-09-25 21:35:27 +02:00
|
|
|
package nodejs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2020-09-30 22:41:52 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/v2/codegen/internal/test"
|
2020-09-25 21:35:27 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGeneratePackage(t *testing.T) {
|
|
|
|
tests := []struct {
|
2020-09-30 01:00:03 +02:00
|
|
|
name string
|
|
|
|
schemaDir string
|
|
|
|
expectedFiles []string
|
2020-09-25 21:35:27 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Simple schema with local resource properties",
|
2020-09-30 01:00:03 +02:00
|
|
|
"simple-resource-schema",
|
|
|
|
[]string{
|
|
|
|
"resource.ts",
|
|
|
|
"otherResource.ts",
|
|
|
|
"argFunction.ts",
|
|
|
|
},
|
2020-09-25 21:35:27 +02:00
|
|
|
},
|
2020-10-08 03:13:10 +02:00
|
|
|
{
|
|
|
|
"Simple schema with enum types",
|
|
|
|
"simple-enum-schema",
|
|
|
|
[]string{
|
2020-12-02 22:45:25 +01:00
|
|
|
"index.ts",
|
2020-10-08 03:13:10 +02:00
|
|
|
"tree/v1/rubberTree.ts",
|
2021-02-26 07:05:02 +01:00
|
|
|
"tree/v1/nursery.ts",
|
2020-10-08 03:13:10 +02:00
|
|
|
"tree/v1/index.ts",
|
|
|
|
"tree/index.ts",
|
|
|
|
"types/input.ts",
|
2020-10-22 19:53:29 +02:00
|
|
|
"types/output.ts",
|
2020-10-08 03:13:10 +02:00
|
|
|
"types/index.ts",
|
|
|
|
"types/enums/index.ts",
|
|
|
|
"types/enums/tree/index.ts",
|
|
|
|
"types/enums/tree/v1/index.ts",
|
|
|
|
},
|
|
|
|
},
|
2021-01-30 01:52:00 +01:00
|
|
|
{
|
|
|
|
"External resource schema",
|
|
|
|
"external-resource-schema",
|
|
|
|
[]string{
|
|
|
|
"index.ts",
|
|
|
|
"argFunction.ts",
|
|
|
|
"cat.ts",
|
|
|
|
"component.ts",
|
|
|
|
"workload.ts",
|
|
|
|
"types/index.ts",
|
|
|
|
"types/input.ts",
|
|
|
|
"types/output.ts",
|
|
|
|
},
|
|
|
|
},
|
2021-03-10 16:08:08 +01:00
|
|
|
{
|
|
|
|
"Simple schema with plain properties",
|
|
|
|
"simple-plain-schema",
|
|
|
|
[]string{
|
|
|
|
"component.ts",
|
|
|
|
"types/input.ts",
|
|
|
|
"types/output.ts",
|
|
|
|
"types/index.ts",
|
|
|
|
},
|
|
|
|
},
|
2020-09-25 21:35:27 +02:00
|
|
|
}
|
2020-09-30 01:00:03 +02:00
|
|
|
testDir := filepath.Join("..", "internal", "test", "testdata")
|
2020-09-25 21:35:27 +02:00
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-09-30 22:41:52 +02:00
|
|
|
files, err := test.GeneratePackageFilesFromSchema(
|
|
|
|
filepath.Join(testDir, tt.schemaDir, "schema.json"), GeneratePackage)
|
2020-09-25 21:35:27 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-10-10 22:47:23 +02:00
|
|
|
expectedFiles, err := test.LoadFiles(filepath.Join(testDir, tt.schemaDir), "nodejs", tt.expectedFiles)
|
2020-09-25 21:35:27 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-09-30 22:41:52 +02:00
|
|
|
test.ValidateFileEquality(t, files, expectedFiles)
|
2020-09-25 21:35:27 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|