I'm trying to mock a call to S3 using the aws-sdk-mock package. I want to mock getObject on a bucket, so that instead of createReadStream() creating a network stream from a bucket, it creates a readable stream from a local file in my test suite.
Here's how I'm mocking the s3 call:
s3Spy = AWS.mock("S3", "getObject", {
createReadStream: () => {
return fs.createReadStream(testDataFile)
}
});
Here's the line where it is used:
const stream = s3.getObject(params).createReadStream();
I can trace stream with a console.log call, and it's clearly a readable:
console.log(stream)
Readable {
_readableState: ReadableState {
...
},
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_read: [Function (anonymous)],
[Symbol(kCapture)]: false
}
However, if I inspect it further, it's not a file readable:
console.log(stream.path)
undefined
Which createReadStream am I calling if it's not the one in my mock? How can I write this so that I pull in the mocked data that I want to use?