Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue#97 - Stream depending on params for S3.getObject #236

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ function mockServiceMethod(service, client, method, replace) {
return promise;
} : undefined,
createReadStream: function() {
if (storedResult instanceof Readable) {
return storedResult;
}
if (replace instanceof Readable) {
return replace;
} else {
Expand Down Expand Up @@ -204,7 +207,7 @@ function mockServiceMethod(service, client, method, replace) {
if (typeof replace === 'function') {
const result = replace.apply(replace, userArgs.concat([callback]));
if (storedResult === undefined && result != null &&
typeof result.then === 'function') {
(typeof result.then === 'function' || result instanceof Readable)) {
storedResult = result
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ test('AWS.mock function should mock AWS service and method on the service', func
st.end();
}));
});
t.test('request object createReadStream works with returned streams', function(st) {
awsMock.mock('S3', 'getObject', () => {
const bodyStream = new Readable();
bodyStream.push('body');
bodyStream.push(null);
return bodyStream;
});
const stream = new AWS.S3().getObject('getObject').createReadStream();
stream.pipe(concatStream(function(actual) {
st.equals(actual.toString(), 'body');
st.end();
}));
});
t.test('request object createReadStream works with strings', function(st) {
awsMock.mock('S3', 'getObject', 'body');
const s3 = new AWS.S3();
Expand Down