Conditions | 4 |
Total Lines | 23 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package utils |
||
15 | func TestGetHomePath(t *testing.T) { |
||
16 | originGetOS := getOS |
||
17 | originUserProfile := os.Getenv("USERPROFILE") |
||
18 | originHome := os.Getenv("HOME") |
||
19 | defer func() { |
||
20 | getOS = originGetOS |
||
21 | os.Setenv("USERPROFILE", originUserProfile) |
||
22 | os.Setenv("HOME", originHome) |
||
23 | }() |
||
24 | |||
25 | getOS = func() string { |
||
26 | return "windows" |
||
27 | } |
||
28 | os.Setenv("USERPROFILE", "/path/to/custom_home") |
||
29 | |||
30 | assert.Equal(t, "/path/to/custom_home", GetHomePath()) |
||
31 | |||
32 | getOS = func() string { |
||
33 | return "darwin" |
||
34 | } |
||
35 | |||
36 | os.Setenv("HOME", "/Users/jacksontian") |
||
37 | assert.Equal(t, "/Users/jacksontian", GetHomePath()) |
||
38 | } |
||
39 |