Skip to content

Commit

Permalink
autoCreate test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Nov 23, 2011
1 parent 3eff84a commit b664978
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions test/autocreate.js
@@ -0,0 +1,69 @@
var test = require('tap').test;
var pushover = require('../');

var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;

var seq = require('seq');

test('create, push to, and clone a repo', function (t) {
t.plan(2);

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 repos = pushover(repoDir);
var port = Math.floor(Math.random() * ((1<<16) - 1e4)) + 1e4;
var server = repos.listen(port);

process.chdir(srcDir);
seq()
.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();
t.end();
})
.catch(t.fail)
;

repos.on('push', function (repo) {
t.equal(repo, 'doom');
});
});
2 changes: 1 addition & 1 deletion test/repos.js
Expand Up @@ -18,7 +18,7 @@ test('create, push to, and clone a repo', function (t) {
fs.mkdirSync(srcDir, 0700);
fs.mkdirSync(dstDir, 0700);

var repos = pushover(repoDir);
var repos = pushover(repoDir, { autoCreate : false });
var port = Math.floor(Math.random() * ((1<<16) - 1e4)) + 1e4;
var server = repos.listen(port);

Expand Down

0 comments on commit b664978

Please sign in to comment.