@@ -164,18 +164,67 @@ describe('Streams', function () {
164
164
} ) ;
165
165
} ) ;
166
166
167
+ // Create a stream processor.
168
+ const createProcessor = async ( name : string ) => {
169
+ const runCmdStub = sinon
170
+ . stub ( mongo . _serviceProvider , 'runCommand' )
171
+ . resolves ( { ok : 1 } ) ;
172
+ const pipeline = [ { $match : { foo : 'bar' } } ] ;
173
+ const processor = await streams . createStreamProcessor ( name , pipeline ) ;
174
+ expect ( processor ) . to . eql ( streams . getProcessor ( name ) ) ;
175
+ const cmd = { createStreamProcessor : name , pipeline } ;
176
+ expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
177
+ return { runCmdStub, processor } ;
178
+ } ;
179
+
180
+ // Validate supplying options in start,stop, and drop commands.
181
+ describe ( 'options' , function ( ) {
182
+ it ( 'supplies options in start, stop, and drop' , async function ( ) {
183
+ const name = 'testOptions' ;
184
+ const { runCmdStub, processor } = await createProcessor ( name ) ;
185
+
186
+ // Start the stream processor with an extra option.
187
+ await processor . start ( { resumeFromCheckpoint : false } ) ;
188
+ expect (
189
+ runCmdStub . calledWithExactly (
190
+ 'admin' ,
191
+ { startStreamProcessor : name , resumeFromCheckpoint : false } ,
192
+ { }
193
+ )
194
+ ) . to . be . true ;
195
+
196
+ // Stop the stream processor with an extra option.
197
+ await processor . stop ( { force : true } ) ;
198
+ expect (
199
+ runCmdStub . calledWithExactly (
200
+ 'admin' ,
201
+ { stopStreamProcessor : name , force : true } ,
202
+ { }
203
+ )
204
+ ) . to . be . true ;
205
+
206
+ // Drop the stream processor with a few extra options.
207
+ const opts = {
208
+ force : true ,
209
+ ttl : { unit : 'day' , size : 30 } ,
210
+ } ;
211
+ await processor . drop ( opts ) ;
212
+ expect (
213
+ runCmdStub . calledWithExactly (
214
+ 'admin' ,
215
+ {
216
+ dropStreamProcessor : name ,
217
+ ...opts ,
218
+ } ,
219
+ { }
220
+ )
221
+ ) . to . be . true ;
222
+ } ) ;
223
+ } ) ;
224
+
167
225
describe ( 'modify' , function ( ) {
168
226
it ( 'throws with invalid parameters' , async function ( ) {
169
- // Create the stream processor.
170
- const runCmdStub = sinon
171
- . stub ( mongo . _serviceProvider , 'runCommand' )
172
- . resolves ( { ok : 1 } ) ;
173
- const name = 'p1' ;
174
- const pipeline = [ { $match : { foo : 'bar' } } ] ;
175
- const processor = await streams . createStreamProcessor ( name , pipeline ) ;
176
- expect ( processor ) . to . eql ( streams . getProcessor ( name ) ) ;
177
- const cmd = { createStreamProcessor : name , pipeline } ;
178
- expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
227
+ const { processor } = await createProcessor ( 'testModify' ) ;
179
228
180
229
// No arguments to modify.
181
230
const caught = await processor
@@ -206,17 +255,8 @@ describe('Streams', function () {
206
255
} ) ;
207
256
208
257
it ( 'works with pipeline and options arguments' , async function ( ) {
209
- const runCmdStub = sinon
210
- . stub ( mongo . _serviceProvider , 'runCommand' )
211
- . resolves ( { ok : 1 } ) ;
212
-
213
- // Create the stream processor.
214
- const name = 'p1' ;
215
- const pipeline = [ { $match : { foo : 'bar' } } ] ;
216
- const processor = await streams . createStreamProcessor ( name , pipeline ) ;
217
- expect ( processor ) . to . eql ( streams . getProcessor ( name ) ) ;
218
- const cmd = { createStreamProcessor : name , pipeline } ;
219
- expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
258
+ const name = 'testModify' ;
259
+ const { runCmdStub, processor } = await createProcessor ( name ) ;
220
260
221
261
// Start the stream processor.
222
262
await processor . start ( ) ;
0 commit comments