Skip to content

Commit d166bc9

Browse files
add test utility for creating processor
1 parent a286168 commit d166bc9

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

packages/shell-api/src/streams.spec.ts

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,24 @@ describe('Streams', function () {
164164
});
165165
});
166166

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+
167180
// Validate supplying options in start,stop, and drop commands.
168181
describe('options', function () {
169182
it('supplies options in start, stop, and drop', async function () {
170-
// Create the stream processor.
171-
const runCmdStub = sinon
172-
.stub(mongo._serviceProvider, 'runCommand')
173-
.resolves({ ok: 1 });
174-
const name = 'optionsTest';
175-
const pipeline = [{ $match: { foo: 'bar' } }];
176-
const processor = await streams.createStreamProcessor(name, pipeline);
177-
expect(processor).to.eql(streams.getProcessor(name));
178-
const cmd = { createStreamProcessor: name, pipeline };
179-
expect(runCmdStub.calledOnceWithExactly('admin', cmd, {})).to.be.true;
183+
const name = 'testOptions';
184+
const { runCmdStub, processor } = await createProcessor(name);
180185

181186
// Start the stream processor with an extra option.
182187
await processor.start({ resumeFromCheckpoint: false });
@@ -219,16 +224,7 @@ describe('Streams', function () {
219224

220225
describe('modify', function () {
221226
it('throws with invalid parameters', async function () {
222-
// Create the stream processor.
223-
const runCmdStub = sinon
224-
.stub(mongo._serviceProvider, 'runCommand')
225-
.resolves({ ok: 1 });
226-
const name = 'p1';
227-
const pipeline = [{ $match: { foo: 'bar' } }];
228-
const processor = await streams.createStreamProcessor(name, pipeline);
229-
expect(processor).to.eql(streams.getProcessor(name));
230-
const cmd = { createStreamProcessor: name, pipeline };
231-
expect(runCmdStub.calledOnceWithExactly('admin', cmd, {})).to.be.true;
227+
const { processor } = await createProcessor('testModify');
232228

233229
// No arguments to modify.
234230
const caught = await processor
@@ -259,17 +255,8 @@ describe('Streams', function () {
259255
});
260256

261257
it('works with pipeline and options arguments', async function () {
262-
const runCmdStub = sinon
263-
.stub(mongo._serviceProvider, 'runCommand')
264-
.resolves({ ok: 1 });
265-
266-
// Create the stream processor.
267-
const name = 'p1';
268-
const pipeline = [{ $match: { foo: 'bar' } }];
269-
const processor = await streams.createStreamProcessor(name, pipeline);
270-
expect(processor).to.eql(streams.getProcessor(name));
271-
const cmd = { createStreamProcessor: name, pipeline };
272-
expect(runCmdStub.calledOnceWithExactly('admin', cmd, {})).to.be.true;
258+
const name = 'testModify';
259+
const { runCmdStub, processor } = await createProcessor(name);
273260

274261
// Start the stream processor.
275262
await processor.start();

0 commit comments

Comments
 (0)