Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Spring3 committed Sep 17, 2018
2 parents 7484025 + d241b12 commit ac5b25f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 57 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
jobs:
build:
docker:
- image: dialonce/nodejs:lts-carbon # the primary container, where your job's commands are run
steps:
- checkout # check out the code in the project directory
- run: apk add --no-cache make python
- run: make deps
- run: make test
## Comment out one permission denied is fixed
# - run: make sonar
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pids
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
# Coverage directory used by tools like nyc
coverage
.sonar/
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand All @@ -34,3 +34,6 @@ node_modules
.idea/
# this file is needed for integration testing
!/test/intergration/.env

# ignore this file since this project is a library
package-lock.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ test
Makefile
sonar-project.properties
gen
.circleci
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ deps:
npm i

lint:
node_modules/.bin/eslint .
npm run lint

test:
make lint
make cover

cover:
node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- test --recursive --timeout=3000
npm run cover

sonar:
sed '/sonar.projectVersion/d' ./sonar-project.properties > tmp && mv tmp sonar-project.properties
echo sonar.projectVersion=`cat package.json | python -c "import json,sys;obj=json.load(sys.stdin);print obj['version'];"` >> sonar-project.properties
wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.8.zip
unzip sonar-scanner-2.8.zip
ifdef CI_PULL_REQUEST
@sonar-scanner-2.8/bin/sonar-runner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL)
@sonar-scanner-2.8/bin/sonar-scanner -e -X -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL)
endif
ifeq ($(CIRCLE_BRANCH),develop)
@sonar-scanner-2.8/bin/sonar-runner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS)
@sonar-scanner-2.8/bin/sonar-scanner -e -X -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS)
endif
rm -rf sonar-scanner-2.8 sonar-scanner-2.8.zip
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It relies on an abstract concept of provider to do the work needed. The only con

## Tests
TO run integration tests (test/integration dir) you must provide 'AWS_ACCESS_KEY_ID', AWS_SECRET_ACCESS_KEY and AWS_REGION env vars

### Examples (S3):
#### Upload (uploads a file to storage)
```js
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "file-management",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple lib to support file operations across projects",
"main": "src/index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "make test"
"lint": "./node_modules/.bin/eslint .",
"cover": "CONSOLE_LOGGING=false ./node_modules/.bin/nyc --reporter=lcov ./node_modules/.bin/_mocha test --recursive --timeout=10000 --exit",
"test": "npm run lint && npm run cover"
},
"repository": {
"type": "git",
Expand All @@ -30,15 +32,15 @@
"devDependencies": {
"chai": "^4.1.0",
"dotenv": "^4.0.0",
"eslint": "^3.16.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"istanbul": "^0.4.5",
"mocha": "^5.2.0"
"eslint": "^5.4.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.1",
"mocha": "^5.2.0",
"nyc": "^12.0.2"
},
"dependencies": {
"aws-sdk": "^2.260.1"
"aws-sdk": "^2.296.0"
}
}
22 changes: 11 additions & 11 deletions src/providers/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class S3Provider extends BaseProvider {
});

return this[s3]
.getObject(params)
.createReadStream()
.on('end', () => resolve(true))
.on('error', error => reject(error))
.pipe(writableStream);
.getObject(params)
.createReadStream()
.on('end', () => resolve(true))
.on('error', error => reject(error))
.pipe(writableStream);
});
}

Expand Down Expand Up @@ -82,12 +82,12 @@ class S3Provider extends BaseProvider {
});

return this[s3]
.deleteObject(params, (err, result) => {
if (err) {
return reject(err);
}
return resolve(result);
});
.deleteObject(params, (err, result) => {
if (err) {
return reject(err);
}
return resolve(result);
});
});
}
}
Expand Down
20 changes: 10 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chai = require('chai');
const fileManagement = require('../src/index');

const BaseProvider = fileManagement.providers.BaseProvider;
const expect = chai.expect;
const { BaseProvider } = fileManagement.providers;
const { expect } = chai;

describe('Mock Provider', () => {
describe('should create a provider and use it', () => {
Expand Down Expand Up @@ -40,16 +40,16 @@ describe('Mock Provider', () => {
const testFile = '/path/to/some/imaginary/file';

it('to upload a file', () => manager
.uploadFile(testFile)
.then((result) => {
expect(result).to.eq(testFile);
}));
.uploadFile(testFile)
.then((result) => {
expect(result).to.eq(testFile);
}));

it('to download a file', () => manager
.downloadFile(testFile)
.then((result) => {
expect(result).to.eq(testFile);
}));
.downloadFile(testFile)
.then((result) => {
expect(result).to.eq(testFile);
}));

it('to delete a file', () => manager.deleteFile(testFile));
});
Expand Down
34 changes: 17 additions & 17 deletions test/intergration/provider-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert');
const fs = require('fs');
const fileManagement = require('../../src/index');

const expect = chai.expect;
const { expect } = chai;

describe('S3 Provider', () => {
describe('should initialize S3 provider and use it', () => {
Expand Down Expand Up @@ -33,27 +33,27 @@ describe('S3 Provider', () => {
it('to upload a file', () => {
const stream = fs.createReadStream('./LICENSE');
return manager
.uploadFile(testLocation, testFileName, stream)
.then((result) => {
expect(result).to.be.an('object').and.to.be.ok;
expect(result.Location).to.be.a('String')
.and.to.include(testFileName)
.and.to.include('dialonce-uploads')
.and.to.include('ci');
});
.uploadFile(testLocation, testFileName, stream)
.then((result) => {
expect(result).to.be.an('object').and.to.be.ok;
expect(result.Location).to.be.a('String')
.and.to.include(testFileName)
.and.to.include('dialonce-uploads')
.and.to.include('ci');
});
});

it('to download a file', () => {
const stream = fs.createWriteStream(testFileName);
return manager
.downloadFile(testLocation, testFileName, stream)
.then(() => {
if (!fs.existsSync(testFileName)) {
throw new Error('File does not exist');
} else {
fs.unlinkSync(testFileName);
}
});
.downloadFile(testLocation, testFileName, stream)
.then(() => {
if (!fs.existsSync(testFileName)) {
throw new Error('File does not exist');
} else {
fs.unlinkSync(testFileName);
}
});
});

it('to delete a file', () => manager.deleteFile(testLocation, testFileName));
Expand Down
4 changes: 2 additions & 2 deletions test/provider-factory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chai = require('chai');
const fileManagement = require('../src/index');

const BaseProvider = fileManagement.providers.BaseProvider;
const expect = chai.expect;
const { BaseProvider } = fileManagement.providers;
const { expect } = chai;

describe('Provider Factory', () => {
expect(fileManagement.providers).to.be.an('object').and.to.be.ok;
Expand Down

0 comments on commit ac5b25f

Please sign in to comment.