@@ -9,15 +9,53 @@ func TestMustGetUserHomeDir_xdxPath(t *testing.T) {
9
9
tests := []struct {
10
10
name string
11
11
}{
12
- {"should return XDX path if available" },
12
+ {"should return XDG path if available" },
13
13
}
14
14
for _ , tt := range tests {
15
15
t .Run (tt .name , func (t * testing.T ) {
16
- _ = os .Setenv ("XDX_CONFIG_HOME" , "abc" )
17
- if got := MustGetUserHomeDir (); got != "abc" {
16
+ _ = os .Setenv ("XDG_CONFIG_HOME" , "abc" )
17
+ _ = SetUserHomeDir ("something_for_just_for_test" )
18
+ if got := MustGetFjiraHomeDir (); got != "abc/fjira" {
18
19
t .Errorf ("MustGetUserHomeDir() = %v, want %v" , got , "abc" )
19
20
}
20
- _ = os .Setenv ("XDX_CONFIG_HOME" , "" )
21
+ _ = os .Setenv ("XDG_CONFIG_HOME" , "" )
22
+ })
23
+ }
24
+ }
25
+
26
+ func TestMustGetUserHomeDir_userHomeWhenExist (t * testing.T ) {
27
+ tests := []struct {
28
+ name string
29
+ }{
30
+ {"should return userHome when exist, and XDG doesn't" },
31
+ }
32
+ for _ , tt := range tests {
33
+ t .Run (tt .name , func (t * testing.T ) {
34
+ _ = os .Setenv ("XDG_CONFIG_HOME" , "abc" )
35
+ _ = SetUserHomeDir ("./something_for_just_for_test" )
36
+ _ = os .MkdirAll ("./something_for_just_for_test/.fjira" , 0750 )
37
+ if got := MustGetFjiraHomeDir (); got != "./something_for_just_for_test/.fjira" {
38
+ t .Errorf ("MustGetUserHomeDir() = %v, want %v" , got , "abc" )
39
+ }
40
+ _ = os .Setenv ("XDG_CONFIG_HOME" , "" )
41
+ _ = os .RemoveAll ("./something_for_just_for_test" )
42
+ })
43
+ }
44
+ }
45
+
46
+ func TestMustGetUserHomeDir_homePath (t * testing.T ) {
47
+ tests := []struct {
48
+ name string
49
+ }{
50
+ {"should return HOME path if available" },
51
+ }
52
+ for _ , tt := range tests {
53
+ t .Run (tt .name , func (t * testing.T ) {
54
+ _ = SetUserHomeDir ("user_home" )
55
+ if got := MustGetFjiraHomeDir (); got != "user_home/.fjira" {
56
+ t .Errorf ("MustGetUserHomeDir() = %v, want %v" , got , "abc" )
57
+ }
58
+ _ = os .Setenv ("HOME" , "" )
21
59
})
22
60
}
23
61
}
0 commit comments