config_okay
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -12,2 +12,3 @@ /*global require module */ | ||
if(e){ | ||
//console.log('got an error',e) | ||
reject(e) | ||
@@ -32,6 +33,9 @@ } | ||
.then( stats => { | ||
if(!stats){ | ||
return reject ('no stats') | ||
} | ||
if(stats.mode.toString(8) != '100600'){ | ||
// if(!stats){ | ||
// return reject ('no stats') | ||
// } | ||
// I can't see how that might happen | ||
// if stat fails, it rejects. if it succeeds, it will | ||
// return a stats object | ||
if(stats.mode.toString(8) !== '100600'){ | ||
return reject ('mode of '+f+' must be 0600') | ||
@@ -43,3 +47,4 @@ } | ||
.catch (e => { | ||
throw (e) | ||
//console.log('caught error',e) | ||
reject (e) | ||
}) | ||
@@ -46,0 +51,0 @@ return null |
{ | ||
"name": "config_okay", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Make sure config files are mode 0600 before you use it", | ||
@@ -10,3 +10,3 @@ "main": "config_okay.js", | ||
"scripts": { | ||
"test": "tap test/**/test*.js" | ||
"test": "tap test/**/test*.js --cov" | ||
}, | ||
@@ -13,0 +13,0 @@ "repository": { |
# config okay | ||
[![Build Status](https://travis-ci.org/jmarca/config_okay.svg?branch=master)](https://travis-ci.org/jmarca/config_okay) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/jmarca/config_okay.svg)](https://greenkeeper.io/) | ||
[![Code Climate](https://codeclimate.com/github/jmarca/config_okay/badges/gpa.svg)](https://codeclimate.com/github/jmarca/config_okay) | ||
This became a module because I used it more than once. | ||
@@ -4,0 +10,0 @@ |
@@ -7,5 +7,3 @@ /* global require console process it describe after before __dirname */ | ||
const denodeify = require('denodeify') | ||
const readFile = denodeify(fs.readFile); | ||
const writeFile = denodeify(fs.writeFile); | ||
const statFile = denodeify(fs.stat); | ||
@@ -30,12 +28,5 @@ const tap = require('tap') | ||
function before(){ | ||
// create a config file | ||
tap.plan(5) | ||
} | ||
tap.plan(3) | ||
tap.test('bad file settings',function (t) { | ||
@@ -80,3 +71,46 @@ | ||
tap.test('croak if a file is not there', function (t) { | ||
return config_okay('file.json') | ||
.then ( result => { | ||
t.fail( 'did not reject .txt file') | ||
return null | ||
}) | ||
.catch( err => { | ||
// console.log('caught error in test as expected',err) | ||
t.match(err,/ENOENT: no such file or directory/,'complaint looks good') | ||
t.pass('did not process a file that does not exist') | ||
t.end() | ||
return null | ||
}) | ||
}) | ||
tap.test('default to config.json if no file specified', function (t) { | ||
return writeFile('config.json',JSON.stringify(good_config) | ||
, {'enconding':'utf8' | ||
,'mode':'0600'}) | ||
.then( () => { | ||
return config_okay() | ||
.then( result => { | ||
t.ok(result) | ||
t.same(result, good_config, 'read back what was put in to config file') | ||
t.end() | ||
return null | ||
}) | ||
.catch( e =>{ | ||
t.fail('did not process valid json file') | ||
t.end() | ||
return null | ||
}) | ||
}) | ||
.then( () => { | ||
return fs.unlinkSync('config.json') | ||
}) | ||
.catch(console.log.bind(console)) | ||
}) | ||
tap.test('read valid json file', function (t) { | ||
@@ -83,0 +117,0 @@ return writeFile(good_file,JSON.stringify(good_config) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52852
17
578
73
1