Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/cli/cli/v2

go 1.23.0
go 1.24

toolchain go1.23.5
toolchain go1.24.4

require (
github.com/AlecAivazis/survey/v2 v2.3.7
Expand Down
7 changes: 3 additions & 4 deletions pkg/cmd/extension/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ import (
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewCmdExtension(t *testing.T) {
tempDir := t.TempDir()
oldWd, _ := os.Getwd()
localExtensionTempDir := filepath.Join(tempDir, "gh-hello")
assert.NoError(t, os.MkdirAll(localExtensionTempDir, 0755))
assert.NoError(t, os.Chdir(localExtensionTempDir))
t.Cleanup(func() { _ = os.Chdir(oldWd) })
require.NoError(t, os.MkdirAll(localExtensionTempDir, 0755))
t.Chdir(localExtensionTempDir)

tests := []struct {
name string
Expand Down
27 changes: 9 additions & 18 deletions pkg/cmd/extension/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1251,9 +1251,10 @@ func TestManager_repo_not_found(t *testing.T) {
}

func TestManager_Create(t *testing.T) {
chdirTemp(t)
tempDir := t.TempDir()
t.Chdir(tempDir)
err := os.MkdirAll("gh-test", 0755)
assert.NoError(t, err)
require.NoError(t, err)

ios, _, stdout, stderr := iostreams.Test()

Expand All @@ -1279,9 +1280,10 @@ func TestManager_Create(t *testing.T) {
}

func TestManager_Create_go_binary(t *testing.T) {
chdirTemp(t)
tempDir := t.TempDir()
t.Chdir(tempDir)
err := os.MkdirAll("gh-test", 0755)
assert.NoError(t, err)
require.NoError(t, err)

reg := httpmock.Registry{}
defer reg.Verify(t)
Expand Down Expand Up @@ -1329,9 +1331,10 @@ func TestManager_Create_go_binary(t *testing.T) {
}

func TestManager_Create_other_binary(t *testing.T) {
chdirTemp(t)
tempDir := t.TempDir()
t.Chdir(tempDir)
err := os.MkdirAll("gh-test", 0755)
assert.NoError(t, err)
require.NoError(t, err)

ios, _, stdout, stderr := iostreams.Test()

Expand Down Expand Up @@ -1392,18 +1395,6 @@ func Test_ensurePrefixed(t *testing.T) {
}
}

// chdirTemp changes the current working directory to a temporary directory for the duration of the test.
func chdirTemp(t *testing.T) {
oldWd, _ := os.Getwd()
tempDir := t.TempDir()
if err := os.Chdir(tempDir); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
_ = os.Chdir(oldWd)
})
}

func fileNames(files []os.DirEntry) []string {
names := make([]string, len(files))
for i, f := range files {
Expand Down
11 changes: 1 addition & 10 deletions pkg/cmd/release/download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ func Test_NewCmdDownload(t *testing.T) {
}

func Test_downloadRun(t *testing.T) {
oldwd, err := os.Getwd()
if err != nil {
t.Fatalf("could not determine working directory: %v", err)
}

tests := []struct {
name string
isTTY bool
Expand Down Expand Up @@ -526,11 +521,7 @@ func Test_downloadRun(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tempDir := t.TempDir()
if err := os.Chdir(tempDir); err == nil {
t.Cleanup(func() { _ = os.Chdir(oldwd) })
} else {
t.Fatal(err)
}
t.Chdir(tempDir)

ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.isTTY)
Expand Down
15 changes: 2 additions & 13 deletions pkg/cmdutil/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,10 @@ func createTestDir(t *testing.T) (cleanupFn func()) {
rootDir := t.TempDir()

// Move workspace to temporary directory
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
err = os.Chdir(rootDir)
if err != nil {
t.Fatal(err)
}
t.Chdir(rootDir)

// Make subdirectories
err = os.Mkdir(filepath.Join(rootDir, "subDir1"), 0755)
err := os.Mkdir(filepath.Join(rootDir, "subDir1"), 0755)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -253,10 +246,6 @@ func createTestDir(t *testing.T) (cleanupFn func()) {

cleanupFn = func() {
os.RemoveAll(rootDir)
err = os.Chdir(cwd)
if err != nil {
t.Fatal(err)
}
}
return cleanupFn
}
Loading