mirror of https://github.com/pulumi/pulumi.git
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
package gen
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v2/codegen/internal/test"
|
|
"github.com/pulumi/pulumi/pkg/v2/codegen/schema"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestInputUsage(t *testing.T) {
|
|
arrayUsage := getInputUsage("FooArray")
|
|
assert.Equal(
|
|
t,
|
|
"FooArrayInput is an input type that accepts FooArray and FooArrayOutput values.\nYou can construct a "+
|
|
"concrete instance of `FooArrayInput` via:\n\n\t\t FooArray{ FooArgs{...} }\n ",
|
|
arrayUsage)
|
|
|
|
mapUsage := getInputUsage("FooMap")
|
|
assert.Equal(
|
|
t,
|
|
"FooMapInput is an input type that accepts FooMap and FooMapOutput values.\nYou can construct a concrete"+
|
|
" instance of `FooMapInput` via:\n\n\t\t FooMap{ \"key\": FooArgs{...} }\n ",
|
|
mapUsage)
|
|
|
|
ptrUsage := getInputUsage("FooPtr")
|
|
assert.Equal(
|
|
t,
|
|
"FooPtrInput is an input type that accepts FooArgs, FooPtr and FooPtrOutput values.\nYou can construct a "+
|
|
"concrete instance of `FooPtrInput` via:\n\n\t\t FooArgs{...}\n\n or:\n\n\t\t nil\n ",
|
|
ptrUsage)
|
|
|
|
usage := getInputUsage("Foo")
|
|
assert.Equal(
|
|
t,
|
|
"FooInput is an input type that accepts FooArgs and FooOutput values.\nYou can construct a concrete instance"+
|
|
" of `FooInput` via:\n\n\t\t FooArgs{...}\n ",
|
|
usage)
|
|
}
|
|
|
|
func TestGoPackageName(t *testing.T) {
|
|
assert.Equal(t, "aws", goPackage("aws"))
|
|
assert.Equal(t, "azure", goPackage("azure-nextgen"))
|
|
assert.Equal(t, "", goPackage(""))
|
|
}
|
|
|
|
// genPkgWrapper adapts the go.GeneratePackage signature to match the expected signature. The signature should be
|
|
// standardized to match the other SDKs, but this hack fixes it for the purposes of this test.
|
|
func genPkgWrapper(tool string, pkg *schema.Package, extraFiles map[string][]byte) (map[string][]byte, error) {
|
|
return GeneratePackage(tool, pkg)
|
|
}
|
|
func TestGeneratePackage(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
schemaDir string
|
|
expectedFiles []string
|
|
}{
|
|
{
|
|
"Simple schema with local resource properties",
|
|
"simple-resource-schema",
|
|
[]string{
|
|
"example/resource.go",
|
|
"example/otherResource.go",
|
|
"example/argFunction.go",
|
|
},
|
|
},
|
|
}
|
|
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"), genPkgWrapper)
|
|
assert.NoError(t, err)
|
|
|
|
expectedFiles, err := test.LoadFiles(filepath.Join(testDir, tt.schemaDir), "go", tt.expectedFiles)
|
|
assert.NoError(t, err)
|
|
|
|
test.ValidateFileEquality(t, files, expectedFiles)
|
|
})
|
|
}
|
|
}
|