New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate Config, replace with StackConfigDir #9145
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
70f5d71
Deprecate Config, replace with StacksDirectory
Frassle b5e05b2
Add to CHANGELOG
Frassle d83d628
lint
Frassle 4fa081f
Table test + error if both keys are given
Frassle c84abfd
Apply Parallel suggestion from Friel
Frassle a812591
Add compat note to changelog
Frassle 9640c02
Remove Parallel
Frassle 3268a8a
Update CHANGELOG_PENDING.md
Frassle 48693f0
Merge remote-tracking branch 'origin/master' into moveConfigOption
Frassle c2658e8
nolint
Frassle 47c26bd
Merge branch 'master' into fraser/renameConfig
Frassle 2d16f7d
Update to stackConfigDir
Frassle 8aee8e4
Update CHANGELOG_PENDING.md
Frassle 73d19f1
Fix symlinks in tests
Frassle File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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,117 @@ | ||
// Copyright 2016-2022, 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 workspace | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// In the tests below we use temporary directories and then expect DetectProjectAndPath to return a path to | ||
// that directory. However DetectProjectAndPath will do symlink resolution, while ioutil.TempDir normally does | ||
// not. This can lead to asserts especially on macos where TmpDir will have returned /var/folders/XX, but | ||
// after sym link resolution that is /private/var/folders/XX. | ||
func mkTempDir(t *testing.T, pattern string) string { | ||
tmpDir, err := ioutil.TempDir("", pattern) | ||
assert.NoError(t, err) | ||
result, err := filepath.EvalSymlinks(tmpDir) | ||
assert.NoError(t, err) | ||
return result | ||
} | ||
|
||
//nolint:paralleltest // Theses test use and change the current working directory | ||
func TestDetectProjectAndPath(t *testing.T) { | ||
tmpDir := mkTempDir(t, "TestDetectProjectAndPath") | ||
cwd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
defer func() { err := os.Chdir(cwd); assert.NoError(t, err) }() | ||
err = os.Chdir(tmpDir) | ||
assert.NoError(t, err) | ||
|
||
yamlPath := filepath.Join(tmpDir, "Pulumi.yaml") | ||
yamlContents := | ||
"name: some_project\ndescription: Some project\nruntime: nodejs\n" | ||
|
||
err = os.WriteFile(yamlPath, []byte(yamlContents), 0600) | ||
assert.NoError(t, err) | ||
|
||
project, path, err := DetectProjectAndPath() | ||
assert.NoError(t, err) | ||
assert.Equal(t, yamlPath, path) | ||
assert.Equal(t, tokens.PackageName("some_project"), project.Name) | ||
assert.Equal(t, "Some project", *project.Description) | ||
assert.Equal(t, "nodejs", project.Runtime.name) | ||
} | ||
|
||
//nolint:paralleltest // Theses test use and change the current working directory | ||
func TestProjectStackPath(t *testing.T) { | ||
Frassle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expectedPath := func(expectedPath string) func(t *testing.T, projectDir, path string, err error) { | ||
return func(t *testing.T, projectDir, path string, err error) { | ||
assert.NoError(t, err) | ||
assert.Equal(t, filepath.Join(projectDir, expectedPath), path) | ||
} | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
yamlContents string | ||
validate func(t *testing.T, projectDir, path string, err error) | ||
}{{ | ||
"WithoutStackConfigDir", | ||
"name: some_project\ndescription: Some project\nruntime: nodejs\n", | ||
expectedPath("Pulumi.my_stack.yaml"), | ||
}, { | ||
"WithStackConfigDir", | ||
"name: some_project\ndescription: Some project\nruntime: nodejs\nstackConfigDir: stacks\n", | ||
expectedPath(filepath.Join("stacks", "Pulumi.my_stack.yaml")), | ||
}, { | ||
"WithConfig", | ||
"name: some_project\ndescription: Some project\nruntime: nodejs\nconfig: stacks\n", | ||
expectedPath(filepath.Join("stacks", "Pulumi.my_stack.yaml")), | ||
}, { | ||
"WithBoth", | ||
"name: some_project\ndescription: Some project\nruntime: nodejs\nconfig: stacksA\nstackConfigDir: stacksB\n", | ||
func(t *testing.T, projectDir, path string, err error) { | ||
assert.Error(t, err) | ||
assert.Equal(t, "can not set `config` and `stackConfigDir`, remove the `config` entry", err.Error()) | ||
}, | ||
}} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
tmpDir := mkTempDir(t, "TestProjectStackPath") | ||
cwd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
defer func() { err := os.Chdir(cwd); assert.NoError(t, err) }() | ||
err = os.Chdir(tmpDir) | ||
assert.NoError(t, err) | ||
|
||
err = os.WriteFile( | ||
filepath.Join(tmpDir, "Pulumi.yaml"), | ||
[]byte(tt.yamlContents), | ||
0600) | ||
assert.NoError(t, err) | ||
|
||
path, err := DetectProjectStackPath("my_stack") | ||
tt.validate(t, tmpDir, path, err) | ||
}) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we issue a deprecation warning, suggesting that the user switches to use
StacksDirectory
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how well that would display, this is called into from a few different places.