Permalink
Browse files

accept test works!

  • Loading branch information...
1 parent 2a2e125 commit f4128d6d4f11981adab6474063605305c0a46069 @substack committed Nov 19, 2011
Showing with 87 additions and 3 deletions.
  1. +8 −3 index.js
  2. +79 −0 test/repos.js
View
@@ -14,13 +14,17 @@ module.exports = function (repoDir, cb) {
var port = Math.floor(Math.random() * ((1<<16) - 1e4) + 1e4);
- dnode(function (remote, conn) {
+ emitter.close = function () {
+ server.close();
+ };
+
+ var server = emitter.server = dnode(function (remote, conn) {
this.emit = function (hookName, args, finish) {
var xs = emitter.listeners(hookName);
if (xs.length === 0) finish(true)
else if (!hook.canAbort[hookName]) {
finish(true);
- emitter.emit(hookName, hook(hookName, args);
+ emitter.emit(hookName, hook(hookName, args));
}
else {
var pending = xs.length;
@@ -35,10 +39,11 @@ module.exports = function (repoDir, cb) {
};
}).listen(port);
- seq(hook.names)
+ seq()
.seq(function () {
fs.writeFile(hookDir + '/.git-emit.port', port.toString(), this);
})
+ .set(hook.names)
.parEach_(function (next, name) {
var file = hookDir + '/' + name;
fs.lstat(file, function (err, s) {
View
@@ -0,0 +1,79 @@
+var test = require('tap').test;
+var pushover = require('pushover');
+var gitEmit = require('../');
+
+var fs = require('fs');
+var path = require('path');
+var spawn = require('child_process').spawn;
+
+var seq = require('seq');
+
+test('accept a patch', function (t) {
+ t.plan(3);
+
+ var repoDir = '/tmp/' + Math.floor(Math.random() * (1<<30)).toString(16);
+ var srcDir = '/tmp/' + Math.floor(Math.random() * (1<<30)).toString(16);
+ var dstDir = '/tmp/' + Math.floor(Math.random() * (1<<30)).toString(16);
+
+ fs.mkdirSync(repoDir, 0700);
+ fs.mkdirSync(srcDir, 0700);
+ fs.mkdirSync(dstDir, 0700);
+
+ var port = Math.floor(Math.random() * ((1<<16) - 1e4)) + 1e4;
+ var repos = pushover(repoDir, this.ok)
+ repos.on('push', function (repo) {
+ t.equal(repo, 'doom');
+ });
+ var server = repos.listen(port);
+
+ process.chdir(srcDir);
+ var repoEmitter;
+ seq()
+ .seq(function () { repos.create('doom', this) })
+ .seq(function () {
+ repoEmitter = gitEmit(repoDir + '/doom', this)
+ repoEmitter.on('update', function (update) {
+ t.ok(true);
+ update.accept();
+ });
+ })
+ .seq(function () {
+ var ps = spawn('git', [ 'init' ]);
+ ps.stderr.pipe(process.stderr, { end : false });
+ ps.on('exit', this.ok);
+ })
+ .seq(function () {
+ fs.writeFile(srcDir + '/a.txt', 'abcd', this);
+ })
+ .seq(function () {
+ spawn('git', [ 'add', 'a.txt' ]).on('exit', this.ok)
+ })
+ .seq(function () {
+ spawn('git', [ 'commit', '-am', 'a!!' ]).on('exit', this.ok)
+ })
+ .seq(function () {
+ var ps = spawn('git', [
+ 'push', 'http://localhost:' + port + '/doom', 'master'
+ ]);
+ ps.stderr.pipe(process.stderr, { end : false });
+ ps.on('exit', this.ok);
+ })
+ .seq(function () {
+ process.chdir(dstDir);
+ spawn('git', [ 'clone', 'http://localhost:' + port + '/doom' ])
+ .on('exit', this.ok)
+ })
+ .seq_(function (next) {
+ path.exists(dstDir + '/doom/a.txt', function (ex) {
+ t.ok(ex, 'a.txt exists');
+ next();
+ })
+ })
+ .seq(function () {
+ server.close();
+ repoEmitter.close();
+ t.end();
+ })
+ .catch(t.fail)
+ ;
+});

0 comments on commit f4128d6

Please sign in to comment.