This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 13 files changed +222
-0
lines changed
13 files changed +222
-0
lines changed Original file line number Diff line number Diff line change @@ -107,5 +107,13 @@ module.exports = (createCommon, options) => {
107
107
} )
108
108
} )
109
109
} )
110
+
111
+ it ( 'should return an error for an invalid CID' , ( ) => {
112
+ return ipfs . block . get ( 'invalid' )
113
+ . then (
114
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
115
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
116
+ )
117
+ } )
110
118
} )
111
119
}
Original file line number Diff line number Diff line change @@ -43,5 +43,21 @@ module.exports = (createCommon, options) => {
43
43
done ( )
44
44
} )
45
45
} )
46
+
47
+ it ( 'should return error for missing argument' , ( ) => {
48
+ return ipfs . block . stat ( null )
49
+ . then (
50
+ ( ) => expect . fail ( 'should have thrown for missing parameter' ) ,
51
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
52
+ )
53
+ } )
54
+
55
+ it ( 'should return error for invalid argument' , ( ) => {
56
+ return ipfs . block . stat ( 'invalid' )
57
+ . then (
58
+ ( ) => expect . fail ( 'should have thrown for invalid parameter' ) ,
59
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
60
+ )
61
+ } )
46
62
} )
47
63
}
Original file line number Diff line number Diff line change @@ -60,5 +60,20 @@ module.exports = (createCommon, options) => {
60
60
done ( )
61
61
} )
62
62
} )
63
+
64
+ it ( 'should prevent duplicate inserts of bootstrap peers' , async ( ) => {
65
+ const removed = await ipfs . bootstrap . rm ( null , { all : true } )
66
+ expect ( removed ) . to . have . property ( 'Peers' ) . that . is . an ( 'array' )
67
+ expect ( removed . Peers ) . to . have . lengthOf ( 0 )
68
+
69
+ const added = await ipfs . bootstrap . add ( validIp4 )
70
+ expect ( added ) . to . have . property ( 'Peers' ) . that . deep . equals ( [ validIp4 ] )
71
+
72
+ const addedAgain = await ipfs . bootstrap . add ( validIp4 )
73
+ expect ( addedAgain ) . to . have . property ( 'Peers' ) . that . deep . equals ( [ validIp4 ] )
74
+
75
+ const list = await ipfs . bootstrap . list ( )
76
+ expect ( list ) . to . have . property ( 'Peers' ) . that . deep . equals ( [ validIp4 ] )
77
+ } )
63
78
} )
64
79
}
Original file line number Diff line number Diff line change @@ -72,6 +72,22 @@ module.exports = (createCommon, options) => {
72
72
} )
73
73
} )
74
74
75
+ it ( 'should set a boolean' , async ( ) => {
76
+ const value = true
77
+ const key = 'Datastore.Path'
78
+
79
+ await ipfs . config . set ( key , value )
80
+ expect ( await ipfs . config . get ( key ) ) . to . equal ( value )
81
+ } )
82
+
83
+ it ( 'should set the other boolean' , async ( ) => {
84
+ const value = false
85
+ const key = 'Datastore.Path'
86
+
87
+ await ipfs . config . set ( key , value )
88
+ expect ( await ipfs . config . get ( key ) ) . to . equal ( value )
89
+ } )
90
+
75
91
it ( 'should set a JSON object' , ( done ) => {
76
92
const key = 'API.HTTPHeaders.Access-Control-Allow-Origin'
77
93
const val = [ 'http://example.io' ]
Original file line number Diff line number Diff line change @@ -91,5 +91,29 @@ module.exports = (createCommon, options) => {
91
91
} )
92
92
} )
93
93
} )
94
+
95
+ it ( 'should list an empty directory' , async ( ) => {
96
+ const testDir = `/test-${ hat ( ) } `
97
+ await ipfs . files . mkdir ( testDir )
98
+ const contents = await ipfs . files . ls ( testDir )
99
+
100
+ expect ( contents ) . to . be . an ( 'array' ) . and . to . be . empty ( )
101
+ } )
102
+
103
+ it ( 'should list an file directly' , async ( ) => {
104
+ const fileName = `single-file-${ hat ( ) } .txt`
105
+ const filePath = `/${ fileName } `
106
+ await ipfs . files . write ( filePath , Buffer . from ( 'Hello world' ) , {
107
+ create : true
108
+ } )
109
+ const contents = await ipfs . files . ls ( filePath )
110
+
111
+ expect ( contents ) . to . be . an ( 'array' ) . and . have . lengthOf ( 1 ) . and . to . deep . equal ( [ {
112
+ hash : '' ,
113
+ name : fileName ,
114
+ size : 0 ,
115
+ type : 0
116
+ } ] )
117
+ } )
94
118
} )
95
119
}
Original file line number Diff line number Diff line change @@ -118,5 +118,21 @@ module.exports = (createCommon, options) => {
118
118
} )
119
119
} )
120
120
} )
121
+
122
+ it ( 'returns error for request without argument' , ( ) => {
123
+ return ipfs . object . data ( null )
124
+ . then (
125
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
126
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
127
+ )
128
+ } )
129
+
130
+ it ( 'returns error for request with invalid argument' , ( ) => {
131
+ ipfs . object . data ( 'invalid' , { enc : 'base58' } )
132
+ . then (
133
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
134
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
135
+ )
136
+ } )
121
137
} )
122
138
}
Original file line number Diff line number Diff line change @@ -336,5 +336,21 @@ module.exports = (createCommon, options) => {
336
336
expect ( meta . fileSize ( ) ) . to . equal ( data . length )
337
337
} )
338
338
} )
339
+
340
+ it ( 'should error for request without argument' , ( ) => {
341
+ return ipfs . object . get ( null )
342
+ . then (
343
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
344
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
345
+ )
346
+ } )
347
+
348
+ it ( 'returns error for request with invalid argument' , ( ) => {
349
+ return ipfs . object . get ( 'invalid' , { enc : 'base58' } )
350
+ . then (
351
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
352
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
353
+ )
354
+ } )
339
355
} )
340
356
}
Original file line number Diff line number Diff line change @@ -206,5 +206,21 @@ module.exports = (createCommon, options) => {
206
206
} )
207
207
} )
208
208
} )
209
+
210
+ it ( 'returns error for request without argument' , ( ) => {
211
+ return ipfs . object . links ( null )
212
+ . then (
213
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
214
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
215
+ )
216
+ } )
217
+
218
+ it ( 'returns error for request with invalid argument' , ( ) => {
219
+ ipfs . object . links ( 'invalid' , { enc : 'base58' } )
220
+ . then (
221
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
222
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
223
+ )
224
+ } )
209
225
} )
210
226
}
Original file line number Diff line number Diff line change @@ -163,5 +163,21 @@ module.exports = (createCommon, options) => {
163
163
164
164
expect ( newParentCid ) . to . eql ( nodeFromObjectPatchCid )
165
165
} )
166
+
167
+ it ( 'returns error for request without arguments' , ( ) => {
168
+ return ipfs . object . patch . addLink ( null , null , null )
169
+ . then (
170
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
171
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
172
+ )
173
+ } )
174
+
175
+ it ( 'returns error for request with only one invalid argument' , ( ) => {
176
+ return ipfs . object . patch . addLink ( 'invalid' , null , null )
177
+ . then (
178
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
179
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
180
+ )
181
+ } )
166
182
} )
167
183
}
Original file line number Diff line number Diff line change @@ -59,5 +59,23 @@ module.exports = (createCommon, options) => {
59
59
60
60
expect ( nodeCid ) . to . not . deep . equal ( patchedNodeCid )
61
61
} )
62
+
63
+ it ( 'returns error for request without key & data' , ( ) => {
64
+ return ipfs . object . patch . appendData ( null , null )
65
+ . then (
66
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
67
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
68
+ )
69
+ } )
70
+
71
+ it ( 'returns error for request without data' , ( ) => {
72
+ const filePath = 'test/fixtures/test-data/badnode.json'
73
+
74
+ return ipfs . object . patch . appendData ( null , filePath )
75
+ . then (
76
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
77
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
78
+ )
79
+ } )
62
80
} )
63
81
}
Original file line number Diff line number Diff line change @@ -121,5 +121,32 @@ module.exports = (createCommon, options) => {
121
121
expect ( withoutChildCid ) . to . not . deep . equal ( parentCid )
122
122
expect ( withoutChildCid ) . to . deep . equal ( nodeCid )
123
123
} )
124
+
125
+ it ( 'returns error for request without arguments' , ( ) => {
126
+ return ipfs . object . patch . rmLink ( null , null )
127
+ . then (
128
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
129
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
130
+ )
131
+ } )
132
+
133
+ it ( 'returns error for request only one invalid argument' , ( ) => {
134
+ return ipfs . object . patch . rmLink ( 'invalid' , null )
135
+ . then (
136
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
137
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
138
+ )
139
+ } )
140
+
141
+ it ( 'returns error for request with invalid first argument' , ( ) => {
142
+ const root = ''
143
+ const link = 'foo'
144
+
145
+ return ipfs . object . patch . rmLink ( root , link )
146
+ . then (
147
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
148
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
149
+ )
150
+ } )
124
151
} )
125
152
}
Original file line number Diff line number Diff line change @@ -68,5 +68,23 @@ module.exports = (createCommon, options) => {
68
68
expect ( nodeCid ) . to . not . deep . equal ( patchedNodeCid )
69
69
expect ( patchedNode . Data ) . to . eql ( patchData )
70
70
} )
71
+
72
+ it ( 'returns error for request without key & data' , ( ) => {
73
+ return ipfs . object . patch . setData ( null , null )
74
+ . then (
75
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
76
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
77
+ )
78
+ } )
79
+
80
+ it ( 'returns error for request without data' , ( ) => {
81
+ const filePath = 'test/fixtures/test-data/badnode.json'
82
+
83
+ return ipfs . object . patch . setData ( null , filePath )
84
+ . then (
85
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
86
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
87
+ )
88
+ } )
71
89
} )
72
90
}
Original file line number Diff line number Diff line change @@ -214,5 +214,21 @@ module.exports = (createCommon, options) => {
214
214
} )
215
215
} )
216
216
} )
217
+
218
+ it ( 'returns error for request without argument' , ( ) => {
219
+ return ipfs . object . stat ( null )
220
+ . then (
221
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
222
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
223
+ )
224
+ } )
225
+
226
+ it ( 'returns error for request with invalid argument' , ( ) => {
227
+ return ipfs . object . stat ( 'invalid' , { enc : 'base58' } )
228
+ . then (
229
+ ( ) => expect . fail ( 'should have returned an error for invalid argument' ) ,
230
+ ( err ) => expect ( err ) . to . be . an . instanceof ( Error )
231
+ )
232
+ } )
217
233
} )
218
234
}
You can’t perform that action at this time.
0 commit comments