mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-14 05:10:10 +08:00
Fixed unit tests
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
## 0.7.0
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
### New Features
|
||||
- New utilities for extending Resource Types.
|
||||
- Added `Resource.extend("ResourceName", { /* members */ })` syntax for extending Resources. The `init()` function is used as a constructor. The old `util.inherits()` syntax will continue to work.
|
||||
@@ -13,4 +11,8 @@
|
||||
- Modules can define multiple Resource Types with `this.addResourceType()`
|
||||
- [TODO] Modules can register their own dashboards.
|
||||
|
||||
### Breaking Changes
|
||||
- All configuration properties on the `Resource` class have been moved to the prototype: `external`, `events`, `label`, `defaultPath`, `basicDashboard`, and `dashboard`.
|
||||
|
||||
|
||||
### Major Bugfixes
|
||||
@@ -34,6 +34,10 @@ module.exports.loadConfig = function(basepath, server, fn) {
|
||||
throw new Error("Error reading app.dpd: " + ex.message);
|
||||
}
|
||||
}
|
||||
}, function(err) {
|
||||
if (err.code === "ENOENT") {
|
||||
throw "Expected app.dpd file";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,7 +132,7 @@ function loadResources(resourceTypesQ, basepath, server) {
|
||||
var type = config.type;
|
||||
if (!types[type]) throw new Error("Cannot find type \"" + type + "\" for resource " + resourceName);
|
||||
|
||||
o = {
|
||||
var o = {
|
||||
config: config
|
||||
, server: server
|
||||
, db: server.db
|
||||
|
||||
@@ -75,7 +75,7 @@ function loadModule(file, fn) {
|
||||
throw ex;
|
||||
}
|
||||
module = module || {};
|
||||
if (!module.id) module.id = path.basename(file, '.js');
|
||||
if (!module.id) module.id = (typeof module === 'function' && module.name) || path.basename(file, '.js');
|
||||
return module;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -32,7 +32,6 @@ function Collection(name, options) {
|
||||
}
|
||||
}
|
||||
util.inherits(Collection, Resource);
|
||||
Collection.id = "Collection";
|
||||
Collection.external = {};
|
||||
Collection.prototype.clientGeneration = true;
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ util.inherits(InternalResources, Resource);
|
||||
module.exports = InternalResources;
|
||||
|
||||
var excludedTypes = {
|
||||
'dashboard': 1,
|
||||
'files': 1,
|
||||
'client-lib': 1,
|
||||
'internal-resources': 1
|
||||
Dashboard: 1,
|
||||
Files: 1,
|
||||
ClientLib: 1,
|
||||
InternalResources: 1
|
||||
};
|
||||
|
||||
InternalResources.prototype.handle = function(ctx, next) {
|
||||
|
||||
@@ -17,6 +17,7 @@ describe('config-loader', function() {
|
||||
sh.rm('-rf', basepath);
|
||||
}
|
||||
sh.mkdir('-p', basepath);
|
||||
('{}').to(path.join(basepath, 'app.dpd'));
|
||||
this.server = new Server();
|
||||
});
|
||||
|
||||
@@ -31,8 +32,9 @@ describe('config-loader', function() {
|
||||
JSON.stringify({type: "Collection", val: 1}).to(path.join(basepath, 'resources/foo/config.json'));
|
||||
JSON.stringify({type: "Collection", val: 2}).to(path.join(basepath, 'resources/bar/config.json'));
|
||||
|
||||
configLoader.loadConfig(basepath, this.server, function(err, resources) {
|
||||
configLoader.loadConfig(basepath, this.server, function(err, result) {
|
||||
if (err) return done(err);
|
||||
var resources = result.resources;
|
||||
expect(resources).to.have.length(6);
|
||||
expect(resources.filter(function(r) { return r.name == 'foo';})).to.have.length(1);
|
||||
expect(resources.filter(function(r) { return r.name == 'bar';})).to.have.length(1);
|
||||
@@ -44,7 +46,10 @@ describe('config-loader', function() {
|
||||
sh.mkdir('-p', path.join(basepath, 'resources/foo'));
|
||||
JSON.stringify({type: "Collection", properties: {}}).to(path.join(basepath, 'resources/foo/config.json'));
|
||||
|
||||
configLoader.loadConfig(basepath, {db: db}, function(err, resourceList) {
|
||||
configLoader.loadConfig(basepath, {db: db}, function(err, result) {
|
||||
|
||||
var resourceList = result.resources;
|
||||
|
||||
expect(resourceList).to.have.length(5);
|
||||
|
||||
expect(resourceList[0].config.properties).to.be.a('object');
|
||||
@@ -57,8 +62,11 @@ describe('config-loader', function() {
|
||||
it('should add internal resources', function(done) {
|
||||
sh.mkdir('-p', path.join(basepath, 'resources'));
|
||||
|
||||
configLoader.loadConfig(basepath, {}, function(err, resourceList) {
|
||||
configLoader.loadConfig(basepath, {}, function(err, result) {
|
||||
if (err) return done(err);
|
||||
|
||||
var resourceList = result.resources;
|
||||
|
||||
expect(resourceList).to.have.length(4);
|
||||
|
||||
expect(resourceList[0] instanceof Files).to.equal(true);
|
||||
|
||||
@@ -41,6 +41,10 @@ describe('resource', function(){
|
||||
describe('.handle(ctx, next)', function(){
|
||||
it('should respond with 200 OK', function(done) {
|
||||
var r = new Resource({path: '/foo'});
|
||||
|
||||
r.get = function(ctx, next) {
|
||||
ctx.done();
|
||||
};
|
||||
|
||||
freq('/foo', null, function (req, res) {
|
||||
r.handle(new Context(r, req, res, {}));
|
||||
|
||||
@@ -10,6 +10,7 @@ describe('Server', function() {
|
||||
sh.cd('./test/support/proj');
|
||||
sh.rm('-rf', 'resources');
|
||||
sh.mkdir('resources');
|
||||
'{}'.to('app.dpd');
|
||||
});
|
||||
|
||||
it('should start a new deployd server', function(done) {
|
||||
|
||||
Reference in New Issue
Block a user