Permalink
Browse files

adding some tests

  • Loading branch information...
1 parent 25efad4 commit a0c67f76dcadf155ae403c8c2984b7052aabefe3 Carlos Rodriguez committed Sep 19, 2012
Showing with 88 additions and 5 deletions.
  1. +1 −1 Makefile
  2. +3 −1 index.js
  3. +4 −1 package.json
  4. +47 −1 test/basic.js
  5. +13 −1 test/common.js
  6. +7 −0 test/fixtures/package.json
  7. +13 −0 test/fixtures/server.js
View
@@ -2,7 +2,7 @@ test:
@./node_modules/.bin/mocha \
--reporter spec \
--bail \
- --timeout 5s \
+ --timeout 60s \
--require test/common.js
.PHONY: test
View
@@ -158,7 +158,9 @@ program
form.append('cmd', spawnCmd);
form.append('args', JSON.stringify(spawnArgs));
form.append('env', JSON.stringify(spawnEnv));
- form.append('commit', commit);
+ if (commit) {
+ form.append('commit', commit);
+ }
if (program.threads) {
form.append('threads', program.threads);
}
View
@@ -15,7 +15,10 @@
"moment": "~1.7.0"
},
"devDependencies": {
- "mocha": "*"
+ "mocha": "*",
+ "amino-drone": "~0.0.0",
+ "idgen": "1.x",
+ "rimraf": "~2.0.2"
},
"scripts": {
"test": "make test"
View
@@ -1,3 +1,49 @@
describe('basic test', function () {
- it('works');
+ var drones = [];
+ before(function (done) {
+ var started = 0;
+ for (var i = 0; i < 3; i++) {
+ (function () {
+ var dir = '/tmp/amino-deploy-test-' + idgen();
+ fs.mkdirSync(dir);
+ var drone = child_process.spawn(path.resolve(__dirname, '../node_modules/.bin/amino-drone'), [dir, '--service', 'deploy-test']);
+ drone.cwd = dir;
+ drone.stdout.on('data', function startListener (chunk) {
+ if (chunk.toString().match(/started/)) {
+ drone.stdout.removeListener('data', startListener);
+ if (++started === 3) {
+ done();
+ }
+ }
+ });
+ process.on('exit', function () {
+ drone.kill();
+ rimraf(drone.cwd, function (err) {});
+ });
+ drones.push(drone);
+ })();
+ }
+ });
+
+ it('shows empty ps', function (done) {
+ child_process.exec(path.resolve(__dirname, '../node_modules/.bin/amino') + ' --service deploy-test ps', function (err, stdout, stderr) {
+ assert.ifError(err);
+ assert(stdout.match(/deploy\-test/));
+ assert.equal(stdout.match(/drone#[a-zA-Z0-9]{8}/g).length, drones.length);
+ assert.equal(stdout.match(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{2,5}/g).length, drones.length);
+ done();
+ });
+ });
+
+ it('spawns', function (done) {
+ var root = path.resolve(__dirname, 'fixtures');
+ var cmd = 'spawn --service deploy-test --threads 1 --drones 2 --root ' + root + ' --env.BAZ=quo -- FOO=bar node server.js --whut';
+ var proc = child_process.exec(path.resolve(__dirname, '../node_modules/.bin/amino') + ' ' + cmd, function (err, stdout, stderr) {
+ assert.ifError(err);
+ assert(stdout.match('found ' + drones.length + ' drones'));
+ assert(stdout.match(/spawned ok/g).length, 2);
+ assert(stdout.match('spawned on 2 drones'));
+ done();
+ });
+ });
});
View
@@ -1,3 +1,15 @@
assert = require('assert');
-util = require('util');
+util = require('util');
+
+fs = require('fs');
+
+child_process = require('child_process');
+
+path = require('path');
+
+idgen = require('idgen');
+
+rimraf = require('rimraf');
+
+amino = require('amino').init();
@@ -0,0 +1,7 @@
+{
+ "name": "amino-deploy-test",
+ "version": "0.0.0",
+ "dependencies": {
+ "lump": "*"
+ }
+}
View
@@ -0,0 +1,13 @@
+var assert = require('assert')
+ , http = require('http')
+ , lump = require('lump')
+
+var server = http.createServer(function (req, res) {
+ assert.equal(process.env.FOO, 'bar');
+ assert.equal(process.env.BAZ, 'quo');
+ assert.equal(process.argv[3], '--whut');
+ res.end('ok');
+});
+server.listen(0, function () {
+ process.stdout.write(String(server.address().port));
+});

0 comments on commit a0c67f7

Please sign in to comment.