pulumi/pkg/codegen/python/gen_resource_mappings_test.go
Ian Wahbe 7f90e12886
Validate Name, Version and Enviroment (#7896)
* Validate Name, Version and Enviroment

For the full path:
Package.Name
Package.Version
Package.Property.Default

* Update tests

* Update CHANGELOG_PENDING.md

* Add more versions to tests

* Add another "Version" field

* Even more "version" tags

* One more "version" tag added

* Update test results from codegen

* Fix py codegen tests

* Fix doc test

* Remove `version` validation

* Unformat json files

* Fail only on errors
2021-09-17 12:12:22 -07:00

70 lines
1.6 KiB
Go

package python
import (
"crypto/md5" //nolint: gosec
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
)
// Regress a problem of non-deterministic codegen (due to reordering).
// The schema is taken from `pulumi-aws` and minified to the smallest
// example that still reproduced the issue.
func TestGenResourceMappingsIsDeterministic(t *testing.T) {
minimalSchema := `
{
"name": "aws",
"version": "0.0.1",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"resources": {
"aws:acm/certificateValidation:CertificateValidation": {},
"aws:acm/certificate:Certificate": {}
},
"language": {
"python": {
"readme": ".."
}
}
}`
var pkgSpec schema.PackageSpec
err := json.Unmarshal([]byte(minimalSchema), &pkgSpec)
if err != nil {
t.Error(err)
return
}
generateInitHash := func() string {
pkg, err := schema.ImportSpec(pkgSpec, nil)
if err != nil {
t.Error(err)
return ""
}
files, err := GeneratePackage("tool", pkg, nil)
if err != nil {
t.Error(err)
return ""
}
file, haveFile := files["pulumi_aws/__init__.py"]
if !haveFile {
t.Error("Cannot find pulumi_aws/__init__.py in the generated files")
return ""
}
return fmt.Sprintf("%x", md5.Sum(file)) //nolint: gosec
}
h1 := generateInitHash()
for i := 0; i < 16; i++ {
assert.Equal(t, h1, generateInitHash())
}
}