chore: adopt t.Chdir for test directory changes#7123
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes Go tests in cli/azd by replacing manual working-directory switching (os.Getwd + os.Chdir + deferred restore) with Go’s t.Chdir, reducing boilerplate and ensuring automatic restoration of the process working directory at test end.
Changes:
- Replaced manual cwd save/restore patterns with
t.Chdiracross several test suites. - Scoped a cwd restoration pattern to a subtest where the code-under-test mutates cwd, ensuring temp dir cleanup remains reliable.
- Updated related test comments to reflect the new isolation approach.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cli/azd/pkg/azdext/extension_command_test.go |
Uses a subtest + t.Chdir to ensure cwd is restored after executing a command that may mutate cwd. |
cli/azd/internal/mcp/tools/azd_yaml_schema_test.go |
Simplifies multiple schema handler tests by using t.Chdir(tmpDir) instead of manual cwd management. |
cli/azd/internal/agent/security/manager_test.go |
Replaces manual cwd handling with t.Chdir in path validation and path resolution tests. |
cli/azd/cmd/init_test.go |
Uses t.Chdir for temp-dir isolation in setupInitAction, removing explicit os.Chdir + cleanup boilerplate. |
You can also share your feedback on Copilot code review. Take the survey.
Replace manual os.Getwd + os.Chdir + defer restore patterns with Go 1.24's t.Chdir which automatically restores the directory when the test completes. Fixes #7095 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9c36dd6 to
ebafc82
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Summary
Fixes #7095