Skip to content

Commit c0de07e

Browse files
chore: switch some CLI Go tests from os.Chdir to t.Chdir
1 parent eacfea0 commit c0de07e

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

pkg/cmd/cmdutil_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ func TestWriteBinaryResponse(t *testing.T) {
6767

6868
func TestCreateDownloadFile(t *testing.T) {
6969
t.Run("creates file with filename from header", func(t *testing.T) {
70-
tmpDir := t.TempDir()
71-
oldWd, _ := os.Getwd()
72-
os.Chdir(tmpDir)
73-
defer os.Chdir(oldWd)
70+
t.Chdir(t.TempDir())
7471

7572
resp := &http.Response{
7673
Header: http.Header{
@@ -96,10 +93,7 @@ func TestCreateDownloadFile(t *testing.T) {
9693
})
9794

9895
t.Run("creates temp file when no header", func(t *testing.T) {
99-
tmpDir := t.TempDir()
100-
oldWd, _ := os.Getwd()
101-
os.Chdir(tmpDir)
102-
defer os.Chdir(oldWd)
96+
t.Chdir(t.TempDir())
10397

10498
resp := &http.Response{Header: http.Header{}}
10599
file, err := createDownloadFile(resp, []byte("test content"))
@@ -109,10 +103,7 @@ func TestCreateDownloadFile(t *testing.T) {
109103
})
110104

111105
t.Run("prevents directory traversal", func(t *testing.T) {
112-
tmpDir := t.TempDir()
113-
oldWd, _ := os.Getwd()
114-
os.Chdir(tmpDir)
115-
defer os.Chdir(oldWd)
106+
t.Chdir(t.TempDir())
116107

117108
resp := &http.Response{
118109
Header: http.Header{

0 commit comments

Comments
 (0)