pulumi/pkg/codegen/python/utilities_test.go
Pat Gavlin 96300f12d9
[codegen/*] Improve range type binding + codegen. (#4552)
- Determine variable types for ranged resources by typechecking an
  equivalent expression
- Detect top-level await in NodeJS and generate an async main
- Fix `pulumi.all` generation for NodeJS
- Fix a bug in the lowering of relative traversals in Python
2020-05-04 15:04:35 -07:00

31 lines
848 B
Go

package python
import (
"strings"
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2"
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/syntax"
"github.com/pulumi/pulumi/pkg/v2/codegen/internal/test"
)
func parseAndBindProgram(t *testing.T, text, name string, options ...hcl2.BindOption) (*hcl2.Program, hcl.Diagnostics) {
parser := syntax.NewParser()
err := parser.ParseFile(strings.NewReader(text), name)
if err != nil {
t.Fatalf("could not read %v: %v", name, err)
}
if parser.Diagnostics.HasErrors() {
t.Fatalf("failed to parse files: %v", parser.Diagnostics)
}
options = append(options, hcl2.PluginHost(test.NewHost(testdataPath)))
program, diags, err := hcl2.BindProgram(parser.Files, options...)
if err != nil {
t.Fatalf("could not bind program: %v", err)
}
return program, diags
}