-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpath_test.go
60 lines (55 loc) · 1.3 KB
/
path_test.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package utils
import (
"os/user"
"path"
"testing"
)
func TestGetDefaultCliConfigPath(t *testing.T) {
// Save original GOOS getter and restore after test
originalGetGOOS := getGOOS
defer func() { getGOOS = originalGetGOOS }()
tests := []struct {
name string
goos string
wantPath string
user *user.User
}{
{
name: "darwin path",
goos: "darwin",
user: &user.User{HomeDir: "/Users/test"},
wantPath: path.Join("/Users/test", "Library/Arduino15", "arduino-cli.yaml"),
},
{
name: "linux path",
goos: "linux",
user: &user.User{HomeDir: "/home/test"},
wantPath: path.Join("/home/test", ".arduino15", "arduino-cli.yaml"),
},
{
name: "windows path",
goos: "windows",
user: &user.User{HomeDir: "C:\\Users\\test"},
wantPath: path.Join("C:\\Users\\test", "AppData\\Local\\Arduino15", "arduino-cli.yaml"),
},
{
name: "nil user",
goos: "linux",
user: nil,
wantPath: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// mocks
getGOOS = tt.goos
userCurrent = func() (*user.User, error) {
return tt.user, nil
}
got := GetDefaultCliConfigPath()
if got != tt.wantPath {
t.Errorf("GetDefaultCliConfigPath() = %v, want %v", got, tt.wantPath)
}
})
}
}