|
| 1 | +package pulumitest_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/pulumi/providertest/pulumitest" |
| 10 | + "github.com/pulumi/providertest/pulumitest/assertup" |
| 11 | + "github.com/pulumi/providertest/pulumitest/opttest" |
| 12 | + "github.com/pulumi/pulumi/sdk/v3/go/common/apitype" |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | +) |
| 15 | + |
| 16 | +var fixedPythonRuntime = ` |
| 17 | +runtime: |
| 18 | + name: python |
| 19 | + options: |
| 20 | + toolchain: pip |
| 21 | + virtualenv: venv |
| 22 | +` |
| 23 | + |
| 24 | +func TestImmediateConvertTypescript(t *testing.T) { |
| 25 | + t.Parallel() |
| 26 | + |
| 27 | + // No need to copy the source, since we're not going to modify it. |
| 28 | + convertResult := pulumitest.Convert(t, filepath.Join("testdata", "yaml_program"), "typescript") |
| 29 | + t.Log(convertResult.Output) |
| 30 | + test := convertResult.PulumiTest |
| 31 | + |
| 32 | + tsPreview := test.Preview(t) |
| 33 | + assert.Equal(t, |
| 34 | + map[apitype.OpType]int{apitype.OpCreate: 2}, |
| 35 | + tsPreview.ChangeSummary) |
| 36 | + |
| 37 | + tsUp := test.Up(t) |
| 38 | + assert.Equal(t, |
| 39 | + map[string]int{"create": 2}, |
| 40 | + *tsUp.Summary.ResourceChanges) |
| 41 | + |
| 42 | + assertup.HasNoDeletes(t, tsUp) |
| 43 | + |
| 44 | + // Show the deploy output. |
| 45 | + t.Log(tsUp.StdOut) |
| 46 | +} |
| 47 | + |
| 48 | +func TestConvertPython(t *testing.T) { |
| 49 | + t.Parallel() |
| 50 | + |
| 51 | + // No need to copy the source, since we're not going to modify it. |
| 52 | + source := pulumitest.NewPulumiTest(t, filepath.Join("testdata", "yaml_program"), opttest.TestInPlace()) |
| 53 | + |
| 54 | + // Convert the original source to Python. |
| 55 | + converted := source.Convert(t, "python", opttest.SkipInstall()).PulumiTest |
| 56 | + assert.NotEqual(t, converted.Source(), source.Source()) |
| 57 | + |
| 58 | + // Fix up the python runtime to use venv. |
| 59 | + config, err := os.ReadFile(filepath.Join(converted.WorkingDir(), "Pulumi.yaml")) |
| 60 | + assert.NoError(t, err) |
| 61 | + config = []byte(strings.Replace(string(config), "runtime: python", fixedPythonRuntime, 1)) |
| 62 | + os.WriteFile(filepath.Join(converted.WorkingDir(), "Pulumi.yaml"), config, 0644) |
| 63 | + |
| 64 | + converted.Install(t) |
| 65 | + |
| 66 | + pythonPreview := converted.Preview(t) |
| 67 | + assert.Equal(t, |
| 68 | + map[apitype.OpType]int{apitype.OpCreate: 2}, |
| 69 | + pythonPreview.ChangeSummary) |
| 70 | + |
| 71 | + pythonUp := converted.Up(t) |
| 72 | + assert.Equal(t, |
| 73 | + map[string]int{"create": 2}, |
| 74 | + *pythonUp.Summary.ResourceChanges) |
| 75 | + |
| 76 | + assertup.HasNoDeletes(t, pythonUp) |
| 77 | + |
| 78 | + // Show the deploy output. |
| 79 | + t.Log(pythonUp.StdOut) |
| 80 | +} |
| 81 | + |
| 82 | +func TestConvertGo(t *testing.T) { |
| 83 | + t.Parallel() |
| 84 | + |
| 85 | + // No need to copy the source, since we're not going to modify it. |
| 86 | + source := pulumitest.NewPulumiTest(t, filepath.Join("testdata", "yaml_program"), opttest.TestInPlace()) |
| 87 | + |
| 88 | + // Convert the original source to Go. |
| 89 | + converted := source.Convert(t, "go").PulumiTest |
| 90 | + assert.NotEqual(t, converted.Source(), source.Source()) |
| 91 | + |
| 92 | + goPreview := converted.Preview(t) |
| 93 | + assert.Equal(t, |
| 94 | + map[apitype.OpType]int{apitype.OpCreate: 2}, |
| 95 | + goPreview.ChangeSummary) |
| 96 | + |
| 97 | + goUp := converted.Up(t) |
| 98 | + assert.Equal(t, |
| 99 | + map[string]int{"create": 2}, |
| 100 | + *goUp.Summary.ResourceChanges) |
| 101 | + |
| 102 | + assertup.HasNoDeletes(t, goUp) |
| 103 | + |
| 104 | + // Show the deploy output. |
| 105 | + t.Log(goUp.StdOut) |
| 106 | +} |
| 107 | + |
| 108 | +func TestConvertTypescript(t *testing.T) { |
| 109 | + t.Parallel() |
| 110 | + |
| 111 | + // No need to copy the source, since we're not going to modify it. |
| 112 | + source := pulumitest.NewPulumiTest(t, filepath.Join("testdata", "yaml_program"), opttest.TestInPlace()) |
| 113 | + |
| 114 | + // Convert the original source to TypeScript. |
| 115 | + converted := source.Convert(t, "typescript").PulumiTest |
| 116 | + assert.NotEqual(t, converted.Source(), source.Source()) |
| 117 | + |
| 118 | + tsPreview := converted.Preview(t) |
| 119 | + assert.Equal(t, |
| 120 | + map[apitype.OpType]int{apitype.OpCreate: 2}, |
| 121 | + tsPreview.ChangeSummary) |
| 122 | + |
| 123 | + tsUp := converted.Up(t) |
| 124 | + assert.Equal(t, |
| 125 | + map[string]int{"create": 2}, |
| 126 | + *tsUp.Summary.ResourceChanges) |
| 127 | + |
| 128 | + assertup.HasNoDeletes(t, tsUp) |
| 129 | + |
| 130 | + // Show the deploy output. |
| 131 | + t.Log(tsUp.StdOut) |
| 132 | +} |
| 133 | + |
| 134 | +func TestConvertCsharp(t *testing.T) { |
| 135 | + t.Parallel() |
| 136 | + |
| 137 | + // No need to copy the source, since we're not going to modify it. |
| 138 | + source := pulumitest.NewPulumiTest(t, filepath.Join("testdata", "yaml_program"), opttest.TestInPlace()) |
| 139 | + |
| 140 | + // Convert the original source to C#. |
| 141 | + converted := source.Convert(t, "csharp").PulumiTest |
| 142 | + assert.NotEqual(t, converted.Source(), source.Source()) |
| 143 | + |
| 144 | + csharpPreview := converted.Preview(t) |
| 145 | + assert.Equal(t, |
| 146 | + map[apitype.OpType]int{apitype.OpCreate: 2}, |
| 147 | + csharpPreview.ChangeSummary) |
| 148 | + |
| 149 | + csharpUp := converted.Up(t) |
| 150 | + assert.Equal(t, |
| 151 | + map[string]int{"create": 2}, |
| 152 | + *csharpUp.Summary.ResourceChanges) |
| 153 | + |
| 154 | + assertup.HasNoDeletes(t, csharpUp) |
| 155 | + |
| 156 | + // Show the deploy output. |
| 157 | + t.Log(csharpUp.StdOut) |
| 158 | +} |
0 commit comments