Skip to content
Snippets Groups Projects
Commit 281aba70 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Added Tests

parent 0b284209
Branches
Tags
1 merge request!1Master
......@@ -52,5 +52,5 @@ It reads from the following sources, performing a deep merge:
## TODO / Missing
- hashicorp values support: if value == "vault:", treat it as secret
- tests
- hashicorp values support: if value == "vault:", treat it as secret
\ No newline at end of file
......@@ -20,22 +20,21 @@ const iterate = function (obj) {
}
}
try {
fs.accessSync(configDefaults)
config = JSON.parse(fs.readFileSync(configDefaults, 'utf8'))
} catch(error) {
console.log('Could not read ' + configDefaults)
console.log('No File ' + configDefaults)
}
try {
fs.accessSync(configLocal)
config = merge(config, JSON.parse(fs.readFileSync(configLocal, 'utf8')))
} catch (error) {
console.log('Could not read ' + configLocal)
console.log('No File ' + configLocal)
}
iterate(config)
module.exports = config
\ No newline at end of file
/* TODO:
* - overwrite
* - env overwrite
*/
const fs = require('fs').promises
let config
let jsonDefaults = {
setting:"defaultvalue",
another: {
setting:"avalue"
}
}
let jsonLocals = {
setting:"localvalue",
another: {
more:"stuff"
}
}
describe('config', function() {
it('should only have values from config.defaults.json', async function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
config = require('./index')
await fs.unlink('config.defaults.json')
expect(config.setting).toBe('defaultvalue')
expect(config.another.setting).toBe('avalue')
})
it('should only have values from config.json', async function() {
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
config = require('./Index')
await fs.unlink('config.json')
expect(config.setting).toBe('localvalue')
expect(config.another.more).toBe('stuff')
})
it('should have both values with preference to config.json', async function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
config = require('./iNdex')
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
expect(config.setting).toBe('localvalue')
expect(config.another.more).toBe('stuff')
expect(config.another.setting).toBe('avalue')
})
it('should have all values with preference to env', async function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
process.env.setting = 'overwritten-by-env'
config = require('./inDex')
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
expect(config.setting).toBe('overwritten-by-env')
expect(config.another.more).toBe('stuff')
expect(config.another.setting).toBe('avalue')
})
})
......@@ -20,5 +20,10 @@
},
"devDependencies": {
"jest": "^25.1.0"
},
"jest": {
"collectCoverage": true,
"coverageReporters": ["json", "lcov", "text", "clover", "html"],
"coverageDirectory": "docs/coverage"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment