@@ -99,6 +99,21 @@ describe('S3Datastore', () => {
99
99
done ( )
100
100
} )
101
101
} )
102
+ it ( 'should return a standard error when the put fails' , ( done ) => {
103
+ const s3 = new S3 ( { params : { Bucket : 'my-ipfs-bucket' } } )
104
+ const store = new S3Store ( '.ipfs/datastore' , { s3 } )
105
+
106
+ standin . replace ( s3 , 'upload' , function ( stand , params , callback ) {
107
+ expect ( params . Key ) . to . equal ( '.ipfs/datastore/z/key' )
108
+ stand . restore ( )
109
+ callback ( new Error ( 'bad things happened' ) )
110
+ } )
111
+
112
+ store . put ( new Key ( '/z/key' ) , Buffer . from ( 'test data' ) , ( err ) => {
113
+ expect ( err . code ) . to . equal ( 'ERR_DB_WRITE_FAILED' )
114
+ done ( )
115
+ } )
116
+ } )
102
117
} )
103
118
104
119
describe ( 'get' , ( ) => {
@@ -114,6 +129,58 @@ describe('S3Datastore', () => {
114
129
115
130
store . get ( new Key ( '/z/key' ) , done )
116
131
} )
132
+ it ( 'should return a standard not found error code if the key isnt found' , ( done ) => {
133
+ const s3 = new S3 ( { params : { Bucket : 'my-ipfs-bucket' } } )
134
+ const store = new S3Store ( '.ipfs/datastore' , { s3 } )
135
+
136
+ standin . replace ( s3 , 'getObject' , function ( stand , params , callback ) {
137
+ expect ( params . Key ) . to . equal ( '.ipfs/datastore/z/key' )
138
+ stand . restore ( )
139
+ let error = new Error ( 'not found' )
140
+ error . statusCode = 404
141
+ callback ( error )
142
+ } )
143
+
144
+ store . get ( new Key ( '/z/key' ) , ( err ) => {
145
+ expect ( err . code ) . to . equal ( 'ERR_NOT_FOUND' )
146
+ done ( )
147
+ } )
148
+ } )
149
+ } )
150
+
151
+ describe ( 'delete' , ( ) => {
152
+ it ( 'should return a standard delete error if deletion fails' , ( done ) => {
153
+ const s3 = new S3 ( { params : { Bucket : 'my-ipfs-bucket' } } )
154
+ const store = new S3Store ( '.ipfs/datastore' , { s3 } )
155
+
156
+ standin . replace ( s3 , 'deleteObject' , function ( stand , params , callback ) {
157
+ expect ( params . Key ) . to . equal ( '.ipfs/datastore/z/key' )
158
+ stand . restore ( )
159
+ callback ( new Error ( 'bad things' ) )
160
+ } )
161
+
162
+ store . delete ( new Key ( '/z/key' ) , ( err ) => {
163
+ expect ( err . code ) . to . equal ( 'ERR_DB_DELETE_FAILED' )
164
+ done ( )
165
+ } )
166
+ } )
167
+ } )
168
+
169
+ describe ( 'open' , ( ) => {
170
+ it ( 'should return a standard open error if the head request fails with an unknown error' , ( done ) => {
171
+ const s3 = new S3 ( { params : { Bucket : 'my-ipfs-bucket' } } )
172
+ const store = new S3Store ( '.ipfs/datastore' , { s3 } )
173
+
174
+ standin . replace ( s3 , 'headObject' , function ( stand , _ , callback ) {
175
+ stand . restore ( )
176
+ callback ( new Error ( 'unknown' ) )
177
+ } )
178
+
179
+ store . open ( ( err ) => {
180
+ expect ( err . code ) . to . equal ( 'ERR_DB_OPEN_FAILED' )
181
+ done ( )
182
+ } )
183
+ } )
117
184
} )
118
185
119
186
describe ( 'interface-datastore' , ( ) => {
0 commit comments