@@ -2,11 +2,13 @@ package shell
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"fmt"
6
- "github.com/cheekybits/is"
7
7
"io/ioutil"
8
8
"os"
9
9
"testing"
10
+
11
+ "github.com/cheekybits/is"
10
12
)
11
13
12
14
func TestMain (m * testing.M ) {
@@ -18,14 +20,14 @@ func TestMain(m *testing.M) {
18
20
os .Exit (1 )
19
21
}
20
22
21
- err = s .FilesWrite (fmt .Sprintf ("/testdata/%s" , f ), file , FilesWrite .Parents (true ), FilesWrite .Create (true ))
23
+ err = s .FilesWrite (context . Background (), fmt .Sprintf ("/testdata/%s" , f ), file , FilesWrite .Parents (true ), FilesWrite .Create (true ))
22
24
if err != nil {
23
25
os .Exit (1 )
24
26
}
25
27
}
26
28
27
29
exitVal := m .Run ()
28
- if err := s .FilesRm ("/testdata" , true ); err != nil {
30
+ if err := s .FilesRm (context . Background (), "/testdata" , true ); err != nil {
29
31
os .Exit (1 )
30
32
}
31
33
os .Exit (exitVal )
@@ -35,17 +37,17 @@ func TestFilesChcid(t *testing.T) {
35
37
is := is .New (t )
36
38
s := NewShell (shellUrl )
37
39
38
- err := s .FilesChcid ("/testdata" , FilesChcid .Hash ("sha3-256" ))
40
+ err := s .FilesChcid (context . Background (), "/testdata" , FilesChcid .Hash ("sha3-256" ))
39
41
is .Nil (err )
40
42
41
- stat , err := s .FilesStat ("/testdata" )
43
+ stat , err := s .FilesStat (context . Background (), "/testdata" )
42
44
is .Nil (err )
43
45
is .Equal (stat .Hash , "bafybmigo44bvq5f4u2oswr7cilvlilftjekr4iilwxuxjj326hchztmk2m" )
44
46
45
- err = s .FilesChcid ("/testdata" , FilesChcid .CidVersion (0 ))
47
+ err = s .FilesChcid (context . Background (), "/testdata" , FilesChcid .CidVersion (0 ))
46
48
is .Nil (err )
47
49
48
- stat , err = s .FilesStat ("/testdata" )
50
+ stat , err = s .FilesStat (context . Background (), "/testdata" )
49
51
is .Nil (err )
50
52
is .Equal (stat .Hash , "QmfZtacPc5nch976ZsiBw6nhLmTzy5JjW2pzZg8j7GjqWq" )
51
53
}
@@ -54,22 +56,22 @@ func TestFilesCp(t *testing.T) {
54
56
is := is .New (t )
55
57
s := NewShell (shellUrl )
56
58
57
- err := s .FilesCp ("/testdata/readme" , "/testdata/readme2" )
59
+ err := s .FilesCp (context . Background (), "/testdata/readme" , "/testdata/readme2" )
58
60
is .Nil (err )
59
61
60
- stat , err := s .FilesStat ("/testdata/readme2" )
62
+ stat , err := s .FilesStat (context . Background (), "/testdata/readme2" )
61
63
is .Nil (err )
62
64
is .Equal (stat .Hash , "QmfZt7xPekp7npSM6DHDUnFseAiNZQs7wq6muH9o99RsCB" )
63
65
64
- err = s .FilesRm ("/testdata/readme2" , true )
66
+ err = s .FilesRm (context . Background (), "/testdata/readme2" , true )
65
67
is .Nil (err )
66
68
}
67
69
68
70
func TestFilesFlush (t * testing.T ) {
69
71
is := is .New (t )
70
72
s := NewShell (shellUrl )
71
73
72
- cid , err := s .FilesFlush ("/testdata" )
74
+ cid , err := s .FilesFlush (context . Background (), "/testdata" )
73
75
is .Nil (err )
74
76
is .Equal (cid , "QmfZtacPc5nch976ZsiBw6nhLmTzy5JjW2pzZg8j7GjqWq" )
75
77
}
@@ -78,7 +80,7 @@ func TestFilesLs(t *testing.T) {
78
80
is := is .New (t )
79
81
s := NewShell (shellUrl )
80
82
81
- list , err := s .FilesLs ("/testdata" , FilesLs .Stat (true ))
83
+ list , err := s .FilesLs (context . Background (), "/testdata" , FilesLs .Stat (true ))
82
84
is .Nil (err )
83
85
84
86
is .Equal (len (list ), 2 )
@@ -92,39 +94,39 @@ func TestFilesMkdir(t *testing.T) {
92
94
is := is .New (t )
93
95
s := NewShell (shellUrl )
94
96
95
- err := s .FilesMkdir ("/testdata/dir1/dir2" , FilesMkdir .Parents (true ), FilesMkdir .CidVersion (1 ), FilesMkdir .Hash ("sha3-256" ))
97
+ err := s .FilesMkdir (context . Background (), "/testdata/dir1/dir2" , FilesMkdir .Parents (true ), FilesMkdir .CidVersion (1 ), FilesMkdir .Hash ("sha3-256" ))
96
98
is .Nil (err )
97
99
98
- err = s .FilesMkdir ("/testdata/dir3/dir4" )
100
+ err = s .FilesMkdir (context . Background (), "/testdata/dir3/dir4" )
99
101
is .NotNil (err )
100
102
101
- err = s .FilesRm ("/testdata/dir1" , true )
103
+ err = s .FilesRm (context . Background (), "/testdata/dir1" , true )
102
104
is .Nil (err )
103
105
}
104
106
105
107
func TestFilesMv (t * testing.T ) {
106
108
is := is .New (t )
107
109
s := NewShell (shellUrl )
108
110
109
- err := s .FilesMv ("/testdata/readme" , "/testdata/readme2" )
111
+ err := s .FilesMv (context . Background (), "/testdata/readme" , "/testdata/readme2" )
110
112
is .Nil (err )
111
113
112
- stat , err := s .FilesStat ("/testdata/readme2" )
114
+ stat , err := s .FilesStat (context . Background (), "/testdata/readme2" )
113
115
is .Nil (err )
114
116
is .Equal (stat .Hash , "QmfZt7xPekp7npSM6DHDUnFseAiNZQs7wq6muH9o99RsCB" )
115
117
116
- stat , err = s .FilesStat ("/testdata/readme" )
118
+ stat , err = s .FilesStat (context . Background (), "/testdata/readme" )
117
119
is .NotNil (err )
118
120
119
- err = s .FilesMv ("/testdata/readme2" , "/testdata/readme" )
121
+ err = s .FilesMv (context . Background (), "/testdata/readme2" , "/testdata/readme" )
120
122
is .Nil (err )
121
123
}
122
124
123
125
func TestFilesRead (t * testing.T ) {
124
126
is := is .New (t )
125
127
s := NewShell (shellUrl )
126
128
127
- reader , err := s .FilesRead ("/testdata/readme" , FilesRead .Offset (0 ), FilesRead .Count (5 ))
129
+ reader , err := s .FilesRead (context . Background (), "/testdata/readme" , FilesRead .Offset (0 ), FilesRead .Count (5 ))
128
130
is .Nil (err )
129
131
130
132
resBytes , err := ioutil .ReadAll (reader )
@@ -137,27 +139,27 @@ func TestFilesRm(t *testing.T) {
137
139
s := NewShell (shellUrl )
138
140
139
141
file , _ := ioutil .ReadFile ("./testdata/ping" )
140
- err := s .FilesWrite ("/testdata/dir1/ping" , bytes .NewBuffer (file ), FilesWrite .Parents (true ), FilesWrite .Create (true ))
142
+ err := s .FilesWrite (context . Background (), "/testdata/dir1/ping" , bytes .NewBuffer (file ), FilesWrite .Parents (true ), FilesWrite .Create (true ))
141
143
is .Nil (err )
142
144
143
- err = s .FilesRm ("/testdata/dir1" , false )
145
+ err = s .FilesRm (context . Background (), "/testdata/dir1" , false )
144
146
is .NotNil (err )
145
147
146
- err = s .FilesRm ("/testdata/dir1" , true )
148
+ err = s .FilesRm (context . Background (), "/testdata/dir1" , true )
147
149
is .Nil (err )
148
150
}
149
151
150
152
func TestFilesStat (t * testing.T ) {
151
153
is := is .New (t )
152
154
s := NewShell (shellUrl )
153
155
154
- res , err := s .FilesStat ("/testdata" )
156
+ res , err := s .FilesStat (context . Background (), "/testdata" )
155
157
is .Nil (err )
156
158
is .Equal (res .Hash , "QmfZtacPc5nch976ZsiBw6nhLmTzy5JjW2pzZg8j7GjqWq" )
157
159
is .Equal (res .Size , 0 )
158
160
is .Equal (res .Type , "directory" )
159
161
160
- res , err = s .FilesStat ("/testdata" , FilesStat .WithLocal (true ))
162
+ res , err = s .FilesStat (context . Background (), "/testdata" , FilesStat .WithLocal (true ))
161
163
is .Nil (err )
162
164
is .Equal (res .WithLocality , true )
163
165
is .Equal (res .Local , true )
@@ -171,21 +173,21 @@ func TestFilesWrite(t *testing.T) {
171
173
file , err := ioutil .ReadFile ("./testdata/ping" )
172
174
is .Nil (err )
173
175
174
- err = s .FilesWrite ("/testdata/ping" , bytes .NewBuffer (file ), FilesWrite .Create (true ), FilesWrite .RawLeaves (true ), FilesWrite .CidVersion (1 ), FilesWrite .Hash ("sha3-256" ))
176
+ err = s .FilesWrite (context . Background (), "/testdata/ping" , bytes .NewBuffer (file ), FilesWrite .Create (true ), FilesWrite .RawLeaves (true ), FilesWrite .CidVersion (1 ), FilesWrite .Hash ("sha3-256" ))
175
177
is .Nil (err )
176
178
177
- reader , err := s .FilesRead ("/testdata/ping" )
179
+ reader , err := s .FilesRead (context . Background (), "/testdata/ping" )
178
180
is .Nil (err )
179
181
180
182
resBytes , err := ioutil .ReadAll (reader )
181
183
is .Nil (err )
182
184
is .Equal (string (resBytes ), "ipfs" )
183
185
184
186
file , err = ioutil .ReadFile ("./testdata/ping" )
185
- err = s .FilesWrite ("/testdata/ping" , bytes .NewBuffer (file ), FilesWrite .Offset (0 ), FilesWrite .Count (2 ), FilesWrite .Truncate (true ))
187
+ err = s .FilesWrite (context . Background (), "/testdata/ping" , bytes .NewBuffer (file ), FilesWrite .Offset (0 ), FilesWrite .Count (2 ), FilesWrite .Truncate (true ))
186
188
is .Nil (err )
187
189
188
- reader , err = s .FilesRead ("/testdata/ping" )
190
+ reader , err = s .FilesRead (context . Background (), "/testdata/ping" )
189
191
is .Nil (err )
190
192
191
193
resBytes , err = ioutil .ReadAll (reader )
0 commit comments