From d3d8451bb4436851afd5740fc133ecc42c4cdcf5 Mon Sep 17 00:00:00 2001 From: aq17 Date: Tue, 1 Nov 2022 11:23:14 -0700 Subject: [PATCH] Test transpiled examples for all languages --- .../batchyaml/gen_program_test.go | 33 +++++++++++++++++++ .../gen_program_test.go | 2 +- .../batchyaml/gen_program_test.go | 32 ++++++++++++++++++ .../batchyaml/gen_program_test.go | 29 ++++++++++++++++ .../cue-random-pp/dotnet/dotnet.csproj | 14 ++++++++ .../dotnet/dotnet.csproj | 14 ++++++++ .../getting-started-pp/dotnet/dotnet.csproj | 14 ++++++++ .../random-pp/dotnet/dotnet.csproj | 14 ++++++++ 8 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 pkg/codegen/dotnet/gen_program_test/batchyaml/gen_program_test.go rename pkg/codegen/go/gen_program_test/{batch_yaml => batchyaml}/gen_program_test.go (98%) create mode 100644 pkg/codegen/nodejs/gen_program_test/batchyaml/gen_program_test.go create mode 100644 pkg/codegen/python/gen_program_test/batchyaml/gen_program_test.go create mode 100644 pkg/codegen/testing/test/testdata/transpiled_examples/cue-random-pp/dotnet/dotnet.csproj create mode 100644 pkg/codegen/testing/test/testdata/transpiled_examples/cue-static-web-app-pp/dotnet/dotnet.csproj create mode 100644 pkg/codegen/testing/test/testdata/transpiled_examples/getting-started-pp/dotnet/dotnet.csproj create mode 100644 pkg/codegen/testing/test/testdata/transpiled_examples/random-pp/dotnet/dotnet.csproj diff --git a/pkg/codegen/dotnet/gen_program_test/batchyaml/gen_program_test.go b/pkg/codegen/dotnet/gen_program_test/batchyaml/gen_program_test.go new file mode 100644 index 000000000000..69fbb2565db0 --- /dev/null +++ b/pkg/codegen/dotnet/gen_program_test/batchyaml/gen_program_test.go @@ -0,0 +1,33 @@ +package batchyaml + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/pulumi/pulumi/pkg/v3/codegen" + codegenDotnet "github.com/pulumi/pulumi/pkg/v3/codegen/dotnet" + "github.com/pulumi/pulumi/pkg/v3/codegen/testing/test" +) + +// This specifically tests the synced examples from pulumi/yaml with +// testing/test/testdata/transpiled_examples, as it requires a different SDK path in Check +func TestGenerateProgram(t *testing.T) { + t.Parallel() + err := os.Chdir("../../../dotnet") // chdir into codegen/dotnet + assert.Nil(t, err) + + test.TestProgramCodegen(t, + test.ProgramCodegenOptions{ + Language: "dotnet", + Extension: "cs", + OutputFile: "Program.cs", + Check: func(t *testing.T, path string, dependencies codegen.StringSet) { + codegenDotnet.Check(t, path, dependencies, "../../../../../../../sdk/dotnet/Pulumi") + }, + GenProgram: codegenDotnet.GenerateProgram, + TestCases: test.PulumiPulumiYAMLProgramTests, + }, + ) +} diff --git a/pkg/codegen/go/gen_program_test/batch_yaml/gen_program_test.go b/pkg/codegen/go/gen_program_test/batchyaml/gen_program_test.go similarity index 98% rename from pkg/codegen/go/gen_program_test/batch_yaml/gen_program_test.go rename to pkg/codegen/go/gen_program_test/batchyaml/gen_program_test.go index e0322739003d..600da0e6498e 100644 --- a/pkg/codegen/go/gen_program_test/batch_yaml/gen_program_test.go +++ b/pkg/codegen/go/gen_program_test/batchyaml/gen_program_test.go @@ -1,4 +1,4 @@ -package batch7 +package batchyaml import ( "os" diff --git a/pkg/codegen/nodejs/gen_program_test/batchyaml/gen_program_test.go b/pkg/codegen/nodejs/gen_program_test/batchyaml/gen_program_test.go new file mode 100644 index 000000000000..1d07d9b30dd8 --- /dev/null +++ b/pkg/codegen/nodejs/gen_program_test/batchyaml/gen_program_test.go @@ -0,0 +1,32 @@ +package batchyaml + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/pulumi/pulumi/pkg/v3/codegen" + codegenNode "github.com/pulumi/pulumi/pkg/v3/codegen/nodejs" + "github.com/pulumi/pulumi/pkg/v3/codegen/testing/test" +) + +// This specifically tests the synced examples from pulumi/yaml with +// testing/test/testdata/transpiled_examples +func TestGenerateProgram(t *testing.T) { + t.Parallel() + err := os.Chdir("../../../nodejs") // chdir into codegen/nodejs + assert.Nil(t, err) + + test.TestProgramCodegen(t, + test.ProgramCodegenOptions{ + Language: "nodejs", + Extension: "ts", + OutputFile: "index.ts", + Check: func(t *testing.T, path string, dependencies codegen.StringSet) { + codegenNode.Check(t, path, dependencies, true) + }, + GenProgram: codegenNode.GenerateProgram, + TestCases: test.PulumiPulumiYAMLProgramTests, + }) +} diff --git a/pkg/codegen/python/gen_program_test/batchyaml/gen_program_test.go b/pkg/codegen/python/gen_program_test/batchyaml/gen_program_test.go new file mode 100644 index 000000000000..9f1f84e856dd --- /dev/null +++ b/pkg/codegen/python/gen_program_test/batchyaml/gen_program_test.go @@ -0,0 +1,29 @@ +package batchyaml + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + codegenPy "github.com/pulumi/pulumi/pkg/v3/codegen/python" + "github.com/pulumi/pulumi/pkg/v3/codegen/testing/test" +) + +// This specifically tests the synced examples from pulumi/yaml with +// testing/test/testdata/transpiled_examples +func TestGenerateProgram(t *testing.T) { + t.Parallel() + err := os.Chdir("../../../python") // chdir into codegen/python + assert.Nil(t, err) + + test.TestProgramCodegen(t, + test.ProgramCodegenOptions{ + Language: "python", + Extension: "py", + OutputFile: "__main__.py", + Check: codegenPy.Check, + GenProgram: codegenPy.GenerateProgram, + TestCases: test.PulumiPulumiYAMLProgramTests, + }) +} diff --git a/pkg/codegen/testing/test/testdata/transpiled_examples/cue-random-pp/dotnet/dotnet.csproj b/pkg/codegen/testing/test/testdata/transpiled_examples/cue-random-pp/dotnet/dotnet.csproj new file mode 100644 index 000000000000..fc7d74b07b24 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/transpiled_examples/cue-random-pp/dotnet/dotnet.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/pkg/codegen/testing/test/testdata/transpiled_examples/cue-static-web-app-pp/dotnet/dotnet.csproj b/pkg/codegen/testing/test/testdata/transpiled_examples/cue-static-web-app-pp/dotnet/dotnet.csproj new file mode 100644 index 000000000000..ca7c203d8e74 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/transpiled_examples/cue-static-web-app-pp/dotnet/dotnet.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/pkg/codegen/testing/test/testdata/transpiled_examples/getting-started-pp/dotnet/dotnet.csproj b/pkg/codegen/testing/test/testdata/transpiled_examples/getting-started-pp/dotnet/dotnet.csproj new file mode 100644 index 000000000000..8eb42744645a --- /dev/null +++ b/pkg/codegen/testing/test/testdata/transpiled_examples/getting-started-pp/dotnet/dotnet.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/pkg/codegen/testing/test/testdata/transpiled_examples/random-pp/dotnet/dotnet.csproj b/pkg/codegen/testing/test/testdata/transpiled_examples/random-pp/dotnet/dotnet.csproj new file mode 100644 index 000000000000..fc7d74b07b24 --- /dev/null +++ b/pkg/codegen/testing/test/testdata/transpiled_examples/random-pp/dotnet/dotnet.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + +