2020-04-07 04:43:16 +02:00
|
|
|
package hcl2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2021-03-17 14:20:05 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax"
|
2021-07-28 03:00:39 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/internal/utils"
|
2020-04-07 04:43:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBindProgram(t *testing.T) {
|
|
|
|
files, err := ioutil.ReadDir(testdataPath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read test data: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
if filepath.Ext(f.Name()) != ".pp" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(f.Name(), func(t *testing.T) {
|
|
|
|
path := filepath.Join(testdataPath, f.Name())
|
|
|
|
contents, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read %v: %v", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parser := syntax.NewParser()
|
|
|
|
err = parser.ParseFile(bytes.NewReader(contents), f.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read %v: %v", path, err)
|
|
|
|
}
|
|
|
|
if parser.Diagnostics.HasErrors() {
|
|
|
|
t.Fatalf("failed to parse files: %v", parser.Diagnostics)
|
|
|
|
}
|
|
|
|
|
2021-07-28 03:00:39 +02:00
|
|
|
_, diags, err := BindProgram(parser.Files, PluginHost(utils.NewHost(testdataPath)))
|
2020-04-07 04:43:16 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if diags.HasErrors() {
|
|
|
|
t.Fatalf("failed to bind program: %v", diags)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|