@@ -4,24 +4,28 @@ import (
4
4
"os"
5
5
"path/filepath"
6
6
"testing"
7
- )
8
7
9
- var (
10
- fakeHome string
11
- fakeIpfs string
8
+ "github.com/ipfs/kubo/config"
12
9
)
13
10
14
11
func TestRepoDir (t * testing.T ) {
15
- fakeHome = t .TempDir ()
16
- os .Setenv ("HOME" , fakeHome )
17
- fakeIpfs = filepath .Join (fakeHome , ".ipfs" )
18
-
19
- t .Run ("testIpfsDir" , testIpfsDir )
20
- t .Run ("testCheckIpfsDir" , testCheckIpfsDir )
21
- t .Run ("testRepoVersion" , testRepoVersion )
12
+ fakeHome := t .TempDir ()
13
+ t .Setenv ("HOME" , fakeHome )
14
+ fakeIpfs := filepath .Join (fakeHome , ".ipfs" )
15
+ t .Setenv (config .EnvDir , fakeIpfs )
16
+
17
+ t .Run ("testIpfsDir" , func (t * testing.T ) {
18
+ testIpfsDir (t , fakeIpfs )
19
+ })
20
+ t .Run ("testCheckIpfsDir" , func (t * testing.T ) {
21
+ testCheckIpfsDir (t , fakeIpfs )
22
+ })
23
+ t .Run ("testRepoVersion" , func (t * testing.T ) {
24
+ testRepoVersion (t , fakeIpfs )
25
+ })
22
26
}
23
27
24
- func testIpfsDir (t * testing.T ) {
28
+ func testIpfsDir (t * testing.T , fakeIpfs string ) {
25
29
_ , err := CheckIpfsDir ("" )
26
30
if err == nil {
27
31
t .Fatal ("expected error when no .ipfs directory to find" )
@@ -37,32 +41,29 @@ func testIpfsDir(t *testing.T) {
37
41
t .Fatal (err )
38
42
}
39
43
if dir != fakeIpfs {
40
- t .Fatal ("wrong ipfs directory:" , dir )
44
+ t .Fatalf ("wrong ipfs directory: got %s, expected %s " , dir , fakeIpfs )
41
45
}
42
46
43
- os .Setenv (envIpfsPath , "~/.ipfs" )
47
+ t .Setenv (config . EnvDir , "~/.ipfs" )
44
48
dir , err = IpfsDir ("" )
45
49
if err != nil {
46
50
t .Fatal (err )
47
51
}
48
52
if dir != fakeIpfs {
49
- t .Fatal ("wrong ipfs directory:" , dir )
53
+ t .Fatalf ("wrong ipfs directory: got %s, expected %s " , dir , fakeIpfs )
50
54
}
51
55
52
56
_ , err = IpfsDir ("~somesuer/foo" )
53
57
if err == nil {
54
58
t .Fatal ("expected error with user-specific home dir" )
55
59
}
56
60
57
- err = os .Setenv (envIpfsPath , "~somesuer/foo" )
58
- if err != nil {
59
- panic (err )
60
- }
61
+ t .Setenv (config .EnvDir , "~somesuer/foo" )
61
62
_ , err = IpfsDir ("~somesuer/foo" )
62
63
if err == nil {
63
64
t .Fatal ("expected error with user-specific home dir" )
64
65
}
65
- err = os .Unsetenv (envIpfsPath )
66
+ err = os .Unsetenv (config . EnvDir )
66
67
if err != nil {
67
68
panic (err )
68
69
}
@@ -72,7 +73,7 @@ func testIpfsDir(t *testing.T) {
72
73
t .Fatal (err )
73
74
}
74
75
if dir != fakeIpfs {
75
- t .Fatal ("wrong ipfs directory:" , dir )
76
+ t .Fatalf ("wrong ipfs directory: got %s, expected %s " , dir , fakeIpfs )
76
77
}
77
78
78
79
_ , err = IpfsDir ("" )
@@ -81,7 +82,7 @@ func testIpfsDir(t *testing.T) {
81
82
}
82
83
}
83
84
84
- func testCheckIpfsDir (t * testing.T ) {
85
+ func testCheckIpfsDir (t * testing.T , fakeIpfs string ) {
85
86
_ , err := CheckIpfsDir ("~somesuer/foo" )
86
87
if err == nil {
87
88
t .Fatal ("expected error with user-specific home dir" )
@@ -101,7 +102,7 @@ func testCheckIpfsDir(t *testing.T) {
101
102
}
102
103
}
103
104
104
- func testRepoVersion (t * testing.T ) {
105
+ func testRepoVersion (t * testing.T , fakeIpfs string ) {
105
106
badDir := "~somesuer/foo"
106
107
_ , err := RepoVersion (badDir )
107
108
if err == nil {
0 commit comments