Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created June 30, 2020 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardonunesp/76384cc324b35f38f57e489e7be4216f to your computer and use it in GitHub Desktop.
Save eduardonunesp/76384cc324b35f38f57e489e7be4216f to your computer and use it in GitHub Desktop.
Using Node.js AWS-SDK + FakeS3 mocking tests
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