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
test: use T.TempDir to create temporary test directory #11524
Conversation
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `ioutil.TempDir` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
PR is now waiting for a maintainer to take action. Note for the maintainer: Commands available:
|
Changelog[uncommitted] (2022-12-03) |
bors merge |
11524: test: use T.TempDir to create temporary test directory r=Frassle a=Juneezee <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> A testing cleanup. This pull request replaces `ioutil.TempDir` with `t.TempDir`. We can use the `T.TempDir` function from the `testing` package to create temporary directory. The directory created by `T.TempDir` is automatically removed when the test and all its subtests complete. Reference: https://pkg.go.dev/testing#T.TempDir ```go func TestFoo(t *testing.T) { // before tmpDir, err := ioutil.TempDir("", "") assert.NoError(t, err) defer os.RemoveAll(tmpDir) // now tmpDir := t.TempDir() } ``` ## Checklist <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] ~~I have added tests that prove my fix is effective or that my feature works~~: Tests refactoring only, no new features added. <!--- User-facing changes require a CHANGELOG entry. --> - [ ] ~~I have updated the [CHANGELOG-PENDING](https://github.com/pulumi/pulumi/blob/master/CHANGELOG_PENDING.md) file with my change~~: This PR is a non user-facing change. <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Service, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] ~~Yes, there are changes in this PR that warrants bumping the Pulumi Service API version~~: N/A <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. --> Co-authored-by: Eng Zer Jun <engzerjun@gmail.com>
Build failed: |
@Frassle The failing test (logs 1) may indicate a potential bug in writing / reading the content of
The format of the directory name returned by However, when we write the project name When we read the project, the project name pulumi/sdk/go/common/workspace/loaders.go Lines 88 to 107 in 712145c
This could be a bug because pulumi/sdk/go/common/workspace/templates.go Lines 594 to 599 in 712145c
Debugging screenshots: Footnotes |
Reference: #11524 (comment) Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Reverted |
Sigh YAML |
bors merge |
Build succeeded: |
Description
A testing cleanup.
This pull request replaces
ioutil.TempDir
witht.TempDir
. We can use theT.TempDir
function from thetesting
package to create temporary directory. The directory created byT.TempDir
is automatically removed when the test and all its subtests complete.Reference: https://pkg.go.dev/testing#T.TempDir
Checklist
I have added tests that prove my fix is effective or that my feature works: Tests refactoring only, no new features added.I have updated the CHANGELOG-PENDING file with my change: This PR is a non user-facing change.Yes, there are changes in this PR that warrants bumping the Pulumi Service API version: N/A