-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_test.go
More file actions
45 lines (38 loc) · 1.41 KB
/
Copy pathpath_test.go
File metadata and controls
45 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"os"
"path/filepath"
"slices"
"testing"
)
func TestMergeExecutablePathPreservesExistingOrderAndAddsMissingPaths(t *testing.T) {
current := filepath.Join("existing", "bin") + string(os.PathListSeparator) + filepath.Join("other", "bin")
extra := filepath.Join("extra", "bin")
got := filepath.SplitList(mergeExecutablePath(current, []string{extra}))
want := []string{filepath.Join("existing", "bin"), filepath.Join("other", "bin"), extra}
if !slices.Equal(got, want) {
t.Fatalf("mergeExecutablePath() = %#v, want %#v", got, want)
}
}
func TestMergeExecutablePathSkipsEmptyAndDuplicatePaths(t *testing.T) {
existing := filepath.Join("existing", "bin")
current := existing + string(os.PathListSeparator) + filepath.Join("other", "bin")
got := filepath.SplitList(mergeExecutablePath(current, []string{"", existing, filepath.Join("existing", ".", "bin")}))
want := filepath.SplitList(current)
if !slices.Equal(got, want) {
t.Fatalf("mergeExecutablePath() = %#v, want %#v", got, want)
}
}
func TestDefaultExecutablePathsIncludeLocalInstallLocations(t *testing.T) {
home := filepath.Join("users", "miya")
paths := defaultExecutablePaths(home)
for _, want := range []string{
filepath.Join(home, ".local", "bin"),
filepath.Join(home, ".bun", "bin"),
filepath.Join(home, "go", "bin"),
} {
if !slices.Contains(paths, want) {
t.Errorf("defaultExecutablePaths() missing %q", want)
}
}
}