Created
June 30, 2020 12:43
-
-
Save eduardonunesp/76384cc324b35f38f57e489e7be4216f to your computer and use it in GitHub Desktop.
Using Node.js AWS-SDK + FakeS3 mocking tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const AWS = require('aws-sdk') | |
const FAKE_S3_HOST = process.env.FAKE_S3_HOST || "localhost" | |
const FAKE_S3_PORT = process.env.FAKE_S3_HOST || "localhost" | |
// Create S3 service object using fakes3 | |
const s3 = new AWS.S3({ | |
region: 'us-east-2', | |
secretAccessKey: '123', | |
accessKeyId: '123', | |
apiVersion: '2006-03-01', | |
endpoint: `http://${FAKE_S3_HOST}:${FAKE_S3_PORT}/`, | |
httpOptions: { | |
proxy: `http://${FAKE_S3_HOST}:${FAKE_S3_PORT}/` | |
} | |
}) | |
describe('Prepare', () => { | |
before((done) => { | |
const fileContent = fs.readFileSync('fixtures/myfile.pdf') | |
const params = { | |
Bucket: 'fakes3', | |
Key: 'myfile.pdf', | |
Body: fileContent | |
} | |
s3.upload(params, (err, data) => { | |
if (err) return done(err) | |
done() | |
}) | |
}) | |
it('Your test', () => {}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment