diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d1e045 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +npm-debug.log +.DS_Store +node_modules diff --git a/package.json b/package.json new file mode 100644 index 0000000..2c7c4c3 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "cascading-service-config", + "version": "0.1.0", + "description": "dry configuration for a multi-service system", + "main": "csc.js", + "scripts": { + "test": "mocha -R spec" + }, + "repository": { + "type": "git", + "url": "http://www.github.com/brikteknologier/cascading-service-config" + }, + "keywords": [ + "service", + "config", + "cascading", + "inherit", + "inheritance", + "protypical", + "protypal", + "dry" + ], + "author": "Jon packer", + "license": "MIT", + "devDependencies": { + "mocha": "~1.13.0" + } +} diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..64141d6 --- /dev/null +++ b/test/test.js @@ -0,0 +1,50 @@ +var csc = require('../'); +var assert = require('assert'); + +var config = { + "neo4j": "http://localhost:7474/", + "internalServiceHostname": "localhost", + "internalServiceProtocol": "http", + "stoutmeal": { + "cookie": "authKey", + "store": { + "type": "redis", + "host": "localhost", + "port": 6379 + } + }, + "stout": { + "defaultUrl": "http://lol.com", + "port": 6005, + "cookieDomain": "localhost" + }, + "sahti": { + "port": 6003 + } +}; + +describe('CSC', function() { + it('should access basic config settings', function() { + var config = csc(config, 'stout'); + assert.equal(config.port, 6005); + assert.equal(config.cookieDomain, "localhost"); + assert.equal(config.defaultUrl, "http://lol.com"); + }); + it('should inherit values on the root object', function() { + var config = csc(config, 'stout'); + assert.equal(config.neo4j, 'http://localhost:7474'); + }); + it('should inherit non-service objects on the root object', function() { + var config = csc(config, 'stout'); + assert.equal(config.stoutmeal.cookie, 'authKey'); + assert.equal(config.stoutmeal.store.type, 'redis'); + }); + it('should transform root service objects to their location', function() { + var config = csc(config, 'stout'); + assert.equal(config.sahti, 'http://localhost:6003'); + }); + it('non-service root objects should also inherit service locations', function() { + var config = csc(config, 'stout'); + assert.equal(config.stoutmeal.stout, 'http://localhost:6005'); + }); +});