@@ -155,6 +155,98 @@ describe('Shard', () => {
155
155
expect ( catchedError ) . to . equal ( expectedError ) ;
156
156
} ) ;
157
157
} ) ;
158
+ describe ( 'reshardCollection' , ( ) => {
159
+ it ( 'calls serviceProvider.runCommandWithCheck without optional args' , async ( ) => {
160
+ await shard . reshardCollection ( 'db.coll' , { key : 1 } ) ;
161
+ expect ( serviceProvider . runCommandWithCheck ) . to . have . been . calledWith (
162
+ ADMIN_DB ,
163
+ {
164
+ reshardCollection : 'db.coll' ,
165
+ key : { key : 1 }
166
+ }
167
+ ) ;
168
+ } ) ;
169
+
170
+ it ( 'calls serviceProvider.runCommandWithCheck with optional args' , async ( ) => {
171
+ await shard . reshardCollection ( 'db.coll' , { key : 1 } , true , { option1 : 1 } ) ;
172
+ expect ( serviceProvider . runCommandWithCheck ) . to . have . been . calledWith (
173
+ ADMIN_DB ,
174
+ {
175
+ reshardCollection : 'db.coll' ,
176
+ key : { key : 1 } ,
177
+ unique : true ,
178
+ option1 : 1
179
+ }
180
+ ) ;
181
+ } ) ;
182
+
183
+ it ( 'returns whatever serviceProvider.runCommandWithCheck returns' , async ( ) => {
184
+ const expectedResult = { ok : 1 } ;
185
+ serviceProvider . runCommandWithCheck . resolves ( expectedResult ) ;
186
+ const result = await shard . reshardCollection ( 'db.coll' , { key : 1 } ) ;
187
+ expect ( result ) . to . deep . equal ( expectedResult ) ;
188
+ } ) ;
189
+
190
+ it ( 'throws if serviceProvider.runCommandWithCheck rejects' , async ( ) => {
191
+ const expectedError = new Error ( ) ;
192
+ serviceProvider . runCommandWithCheck . rejects ( expectedError ) ;
193
+ const catchedError = await shard . reshardCollection ( 'db.coll' , { key : 1 } )
194
+ . catch ( e => e ) ;
195
+ expect ( catchedError ) . to . equal ( expectedError ) ;
196
+ } ) ;
197
+ } ) ;
198
+ describe ( 'commitReshardCollection' , ( ) => {
199
+ it ( 'calls serviceProvider.runCommandWithCheck' , async ( ) => {
200
+ await shard . commitReshardCollection ( 'db.coll' ) ;
201
+ expect ( serviceProvider . runCommandWithCheck ) . to . have . been . calledWith (
202
+ ADMIN_DB ,
203
+ {
204
+ commitReshardCollection : 'db.coll'
205
+ }
206
+ ) ;
207
+ } ) ;
208
+
209
+ it ( 'returns whatever serviceProvider.runCommandWithCheck returns' , async ( ) => {
210
+ const expectedResult = { ok : 1 } ;
211
+ serviceProvider . runCommandWithCheck . resolves ( expectedResult ) ;
212
+ const result = await shard . commitReshardCollection ( 'db.coll' ) ;
213
+ expect ( result ) . to . deep . equal ( expectedResult ) ;
214
+ } ) ;
215
+
216
+ it ( 'throws if serviceProvider.runCommandWithCheck rejects' , async ( ) => {
217
+ const expectedError = new Error ( ) ;
218
+ serviceProvider . runCommandWithCheck . rejects ( expectedError ) ;
219
+ const catchedError = await shard . commitReshardCollection ( 'db.coll' )
220
+ . catch ( e => e ) ;
221
+ expect ( catchedError ) . to . equal ( expectedError ) ;
222
+ } ) ;
223
+ } ) ;
224
+ describe ( 'abortReshardCollection' , ( ) => {
225
+ it ( 'calls serviceProvider.runCommandWithCheck' , async ( ) => {
226
+ await shard . abortReshardCollection ( 'db.coll' ) ;
227
+ expect ( serviceProvider . runCommandWithCheck ) . to . have . been . calledWith (
228
+ ADMIN_DB ,
229
+ {
230
+ abortReshardCollection : 'db.coll'
231
+ }
232
+ ) ;
233
+ } ) ;
234
+
235
+ it ( 'returns whatever serviceProvider.runCommandWithCheck returns' , async ( ) => {
236
+ const expectedResult = { ok : 1 } ;
237
+ serviceProvider . runCommandWithCheck . resolves ( expectedResult ) ;
238
+ const result = await shard . abortReshardCollection ( 'db.coll' ) ;
239
+ expect ( result ) . to . deep . equal ( expectedResult ) ;
240
+ } ) ;
241
+
242
+ it ( 'throws if serviceProvider.runCommandWithCheck rejects' , async ( ) => {
243
+ const expectedError = new Error ( ) ;
244
+ serviceProvider . runCommandWithCheck . rejects ( expectedError ) ;
245
+ const catchedError = await shard . abortReshardCollection ( 'db.coll' )
246
+ . catch ( e => e ) ;
247
+ expect ( catchedError ) . to . equal ( expectedError ) ;
248
+ } ) ;
249
+ } ) ;
158
250
describe ( 'addShard' , ( ) => {
159
251
it ( 'calls serviceProvider.runCommandWithCheck with arg' , async ( ) => {
160
252
serviceProvider . runCommandWithCheck . resolves ( { ok : 1 , msg : 'isdbgrid' } ) ;
0 commit comments