@@ -13,6 +13,10 @@ const fileA = isNode
13
13
? fs . readFileSync ( process . cwd ( ) + '/test/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data' )
14
14
: require ( 'buffer!./test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data' )
15
15
16
+ const fileAExt = isNode
17
+ ? fs . readFileSync ( process . cwd ( ) + '/test/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.ext' )
18
+ : require ( 'buffer!./test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.ext' )
19
+
16
20
module . exports = function ( repo ) {
17
21
describe ( 'IPFS Repo Tests' , function ( ) {
18
22
it ( 'check if Repo exists' , ( done ) => {
@@ -109,6 +113,7 @@ module.exports = function (repo) {
109
113
110
114
describe ( 'datastore' , function ( ) {
111
115
const baseFileHash = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'
116
+ const baseExtFileHash = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe'
112
117
113
118
it ( 'reads block' , function ( done ) {
114
119
const buf = new Buffer ( base58 . decode ( baseFileHash ) )
@@ -120,6 +125,16 @@ module.exports = function (repo) {
120
125
} ) )
121
126
} )
122
127
128
+ it ( 'reads block, with custom extension' , function ( done ) {
129
+ const buf = new Buffer ( base58 . decode ( baseFileHash ) )
130
+ repo . datastore . createReadStream ( buf , 'ext' )
131
+ . pipe ( bl ( ( err , data ) => {
132
+ expect ( err ) . to . not . exist
133
+ expect ( data . equals ( fileAExt ) ) . to . equal ( true )
134
+ done ( )
135
+ } ) )
136
+ } )
137
+
123
138
it ( 'write a block' , function ( done ) {
124
139
const rnd = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVtesthash'
125
140
const mh = new Buffer ( base58 . decode ( rnd ) )
@@ -132,6 +147,18 @@ module.exports = function (repo) {
132
147
} ) . end ( data )
133
148
} )
134
149
150
+ it ( 'write a block with custom extension' , function ( done ) {
151
+ const rnd = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVtesthash'
152
+ const mh = new Buffer ( base58 . decode ( rnd ) )
153
+ const data = new Buffer ( 'Oh the data' )
154
+
155
+ repo . datastore . createWriteStream ( mh , 'ext' , ( err , metadata ) => {
156
+ expect ( err ) . to . not . exist
157
+ expect ( metadata . key ) . to . equal ( '12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07605f55537ce990.ext' )
158
+ done ( )
159
+ } ) . end ( data )
160
+ } )
161
+
135
162
it ( 'block exists' , function ( done ) {
136
163
const buf = new Buffer ( base58 . decode ( baseFileHash ) )
137
164
@@ -142,6 +169,16 @@ module.exports = function (repo) {
142
169
} )
143
170
} )
144
171
172
+ it ( 'block exists, with custom extension' , function ( done ) {
173
+ const buf = new Buffer ( base58 . decode ( baseExtFileHash ) )
174
+
175
+ repo . datastore . exists ( buf , 'ext' , ( err , exists ) => {
176
+ expect ( err ) . to . not . exist
177
+ expect ( exists ) . to . equal ( true )
178
+ done ( )
179
+ } )
180
+ } )
181
+
145
182
it ( 'check for non existent block' , function ( done ) {
146
183
const buf = new Buffer ( 'random buffer' )
147
184
@@ -163,6 +200,18 @@ module.exports = function (repo) {
163
200
} )
164
201
} )
165
202
} )
203
+
204
+ it ( 'remove a block, with custom extension' , function ( done ) {
205
+ const buf = new Buffer ( base58 . decode ( baseExtFileHash ) )
206
+ repo . datastore . remove ( buf , 'ext' , ( err ) => {
207
+ expect ( err ) . to . not . exist
208
+ repo . datastore . exists ( buf , 'ext' , ( err , exists ) => {
209
+ expect ( err ) . to . not . exist
210
+ expect ( exists ) . to . equal ( false )
211
+ done ( )
212
+ } )
213
+ } )
214
+ } )
166
215
} )
167
216
168
217
describe ( 'datastore-legacy' , ( ) => { } )
0 commit comments