Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 18, 2022
1 parent 81fa291 commit 15f9858
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/codegen/report/report_test.go
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{}) {}

0 comments on commit 15f9858

Please sign in to comment.