pulumi/pkg/codegen/python/gen_test.go
2020-10-10 13:47:23 -07:00

68 lines
1.5 KiB
Go

package python
import (
"path/filepath"
"testing"
"github.com/pulumi/pulumi/pkg/v2/codegen/internal/test"
"github.com/stretchr/testify/assert"
)
var pathTests = []struct {
input string
expected string
}{
{".", "."},
{"", "."},
{"../", ".."},
{"../..", "..."},
{"../../..", "...."},
{"something", ".something"},
{"../parent", "..parent"},
{"../../module", "...module"},
}
func TestRelPathToRelImport(t *testing.T) {
for _, tt := range pathTests {
t.Run(tt.input, func(t *testing.T) {
result := relPathToRelImport(tt.input)
if result != tt.expected {
t.Errorf("expected \"%s\"; got \"%s\"", tt.expected, result)
}
})
}
}
func TestGeneratePackage(t *testing.T) {
tests := []struct {
name string
schemaDir string
expectedFiles []string
}{
{
"Simple schema with local resource properties",
"simple-resource-schema",
[]string{
filepath.Join("pulumi_example", "resource.py"),
filepath.Join("pulumi_example", "other_resource.py"),
filepath.Join("pulumi_example", "arg_function.py"),
},
},
}
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), "python", tt.expectedFiles)
assert.NoError(t, err)
test.ValidateFileEquality(t, files, expectedFiles)
})
}
}