-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package report_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi/pkg/v3/codegen/dotnet" | ||
"github.com/pulumi/pulumi/pkg/v3/codegen/hcl2/syntax" | ||
"github.com/pulumi/pulumi/pkg/v3/codegen/nodejs" | ||
"github.com/pulumi/pulumi/pkg/v3/codegen/pcl" | ||
"github.com/pulumi/pulumi/pkg/v3/codegen/report" | ||
"github.com/pulumi/pulumi/pkg/v3/version" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReportExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
reporter := report.New("example", version.Version) | ||
defer reporter.Close() | ||
|
||
examples := []struct { | ||
title string | ||
body string | ||
}{ | ||
{"Our basic bucket", `resource bucket "aws:s3:BucketV2" { }`}, | ||
{"A resource group", `resource group "azure:core:ResourceGroup" { location: "westus2" }`}, | ||
} | ||
for _, example := range examples { | ||
parser := syntax.NewParser() | ||
err := parser.ParseFile(bytes.NewReader([]byte(example.body)), example.title) | ||
require.NoError(t, err, "parse failed") | ||
program, diags, err := pcl.BindProgram(parser.Files) | ||
require.NoError(t, err) | ||
require.False(t, diags.HasErrors(), diags) | ||
|
||
langs := []string{"dotnet", "nodejs"} | ||
for i, genFn := range []report.GenerateProgramFn{dotnet.GenerateProgram, nodejs.GenerateProgram} { | ||
program, diags, err := reporter.Report(example.title, langs[i], parser.Files, genFn)(program) | ||
handleAsNormal(program, diags, err) | ||
} | ||
} | ||
|
||
assert.Equal(t, report.Summary{ | ||
Name: "example", | ||
Stats: report.Stats{ | ||
NumConversions: 4, | ||
Successes: 4, | ||
}, | ||
Languages: map[string]*report.Language{ | ||
"dotnet": { | ||
Stats: report.Stats{ | ||
NumConversions: 2, | ||
Successes: 2, | ||
}, | ||
}, | ||
"nodejs": { | ||
Stats: report.Stats{ | ||
NumConversions: 2, | ||
Successes: 2, | ||
}, | ||
}, | ||
}, | ||
}, reporter.Summary()) | ||
} | ||
|
||
func handleAsNormal(args ...interface{}) {} |