Skip to content

Commit 79f5b90

Browse files
committed
test(cmd): fix TestDetectInstallMethod_Go failing when HOME is not set
1 parent 3145f1b commit 79f5b90

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

cmd/43.self-update_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"os"
1010
"os/exec"
11-
"path/filepath"
1211
"testing"
1312

1413
"github.com/stretchr/testify/assert"
@@ -99,12 +98,12 @@ func TestDetectInstallMethod_Cargo(t *testing.T) {
9998
}
10099

101100
func TestDetectInstallMethod_Go(t *testing.T) {
102-
// isGoInstall checks against actual GOPATH/bin or ~/go/bin, so construct
103-
// paths using the real home directory so the assertion is reliable.
104-
home, err := os.UserHomeDir()
105-
require.NoError(t, err)
101+
// Set a mock GOPATH so we can deterministically test detection
102+
// without relying on os.UserHomeDir (which fails if $HOME is not set).
103+
t.Setenv("GOPATH", "/mock/gopath")
104+
106105
paths := []string{
107-
filepath.Join(home, "go", "bin", "unirtm"),
106+
"/mock/gopath/bin/unirtm",
108107
}
109108
for _, p := range paths {
110109
assert.Equal(t, installMethodGo, detectInstallMethod(p), "path: %s", p)

0 commit comments

Comments
 (0)