Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add tests for project and stack edits
- Loading branch information
1 parent
c5d4f55
commit 166a652
Showing
1 changed file
with
181 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,181 @@ | ||
// Copyright 2016-2021, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/hexops/autogold" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pulumi/pulumi/pkg/v3/testing/integration" | ||
ptesting "github.com/pulumi/pulumi/sdk/v3/go/common/testing" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace" | ||
) | ||
|
||
func TestProjectRoundtripComments(t *testing.T) { | ||
t.Parallel() | ||
|
||
e := ptesting.NewEnvironment(t) | ||
defer func() { | ||
if !t.Failed() { | ||
e.DeleteEnvironment() | ||
} | ||
}() | ||
|
||
pulumiProject := ` | ||
# 馃敶 header comment | ||
name: pulumi-test | ||
runtime: yaml | ||
config: | ||
first-value: | ||
type: string | ||
default: first | ||
second-value: | ||
type: string | ||
third-value: | ||
type: array | ||
items: | ||
type: string | ||
default: [third] # 馃煚 comment after array | ||
# 馃煛 comment before resources | ||
resources: | ||
my-bucket: | ||
type: aws:s3:bucket | ||
# 馃煝 comment before props, note the indentation is excessive, will change to 2 spaces | ||
properties: | ||
# 馃數 comment before prop | ||
bucket: test-123 # 馃煟 comment after prop | ||
# 馃煡 footer comment | ||
` | ||
|
||
integration.CreatePulumiRepo(e, pulumiProject) | ||
projFilename := filepath.Join(e.CWD, fmt.Sprintf("%s.yaml", workspace.ProjectFile)) | ||
// TODO: Replace this with config set --project after implemented. | ||
proj, err := workspace.LoadProject(projFilename) | ||
require.NoError(t, err) | ||
ty := "string" | ||
proj.Config["new-value"] = workspace.ProjectConfigType{ | ||
Type: &ty, | ||
Description: "馃挏 a new value added to config, expect unicode to be escaped", | ||
} | ||
err = proj.Save(projFilename) | ||
require.NoError(t, err) | ||
|
||
projData, err := os.ReadFile(projFilename) | ||
require.NoError(t, err) | ||
|
||
// Project file: | ||
want := autogold.Want("roundtrip-project", `# 馃敶 header comment | ||
name: pulumi-test | ||
runtime: yaml | ||
config: | ||
first-value: | ||
type: string | ||
default: first | ||
new-value: | ||
type: string | ||
description: "\U0001F49C a new value added to config, expect unicode to be escaped" | ||
second-value: | ||
type: string | ||
third-value: | ||
type: array | ||
items: | ||
type: string | ||
default: [third] # 馃煚 comment after array | ||
# 馃煛 comment before resources | ||
resources: | ||
my-bucket: | ||
# 馃煝 comment before props, note the indentation is excessive, will change to 2 spaces | ||
properties: | ||
# 馃數 comment before prop | ||
bucket: test-123 # 馃煟 comment after prop | ||
type: aws:s3:bucket | ||
# 馃煡 footer comment | ||
`) | ||
want.Equal(t, string(projData)) | ||
} | ||
|
||
func TestConfigRoundtripComments(t *testing.T) { | ||
t.Parallel() | ||
|
||
e := ptesting.NewEnvironment(t) | ||
defer func() { | ||
if !t.Failed() { | ||
e.DeleteEnvironment() | ||
} | ||
}() | ||
|
||
pulumiProject := ` | ||
name: foo | ||
runtime: yaml | ||
` | ||
|
||
integration.CreatePulumiRepo(e, pulumiProject) | ||
e.SetBackend(e.LocalURL()) | ||
e.RunCommand("pulumi", "stack", "init", "test") | ||
e.Passphrase = "TestConfigRoundtripComments" | ||
configFilename := filepath.Join(e.CWD, fmt.Sprintf("%s.test.yaml", workspace.ProjectFile)) | ||
|
||
os.WriteFile(configFilename, []byte(` | ||
encryptionsalt: v1:ThS5UPxP9qc=:v1:UZYAXF+ylaJ0rGhv:9OTvBnOEDFgxs7btjzSu+LZ470vLpg== | ||
# 馃敶 header comment | ||
config: | ||
foo:a: some-value # 馃煚 comment after value | ||
# 馃煛 comment before key | ||
foo:b: some-value | ||
foo:c: | ||
a: A | ||
b: B | ||
c: | ||
- 1 | ||
- 2 | ||
- 3 # 馃煝 comment in array | ||
# 馃數 comment after array | ||
foo:d: | ||
secure: v1:T1ftqhY0hqr+EJK6:+jvd5PMecFx80tcavzuZY4tLatgIfoe/xR72GA== # 馃煟 comment on secret | ||
# 馃煡 footer comment`), 0600) | ||
e.RunCommand("pulumi", "config", "set", "e", "E") | ||
|
||
projData, err := os.ReadFile(configFilename) | ||
require.NoError(t, err) | ||
|
||
// Project file: | ||
want := autogold.Want("roundtrip-config", `encryptionsalt: v1:ThS5UPxP9qc=:v1:UZYAXF+ylaJ0rGhv:9OTvBnOEDFgxs7btjzSu+LZ470vLpg== | ||
# 馃敶 header comment | ||
config: | ||
foo:a: some-value # 馃煚 comment after value | ||
# 馃煛 comment before key | ||
foo:b: some-value | ||
foo:c: | ||
a: A | ||
b: B | ||
c: | ||
- 1 | ||
- 2 | ||
- 3 # 馃煝 comment in array | ||
# 馃數 comment after array | ||
foo:d: | ||
secure: v1:T1ftqhY0hqr+EJK6:+jvd5PMecFx80tcavzuZY4tLatgIfoe/xR72GA== # 馃煟 comment on secret | ||
foo:e: E | ||
# 馃煡 footer comment | ||
`) | ||
want.Equal(t, string(projData)) | ||
} |