Permalink
Browse files

failing multi test

  • Loading branch information...
1 parent cfdda6d commit 575a3404174ea50b6dbfbf9cfcec252945e1b2d5 @substack committed Apr 3, 2013
Showing with 105 additions and 0 deletions.
  1. +6 −0 test/commit/multi.sh
  2. +99 −0 test/multi.js
View
@@ -0,0 +1,6 @@
+#!/bin/bash
+git checkout -b staging
+sed -i 's/BEEP/dino/g' beep.js
+sed -i 's/BOOP/saur/g' boop.js
+git add beep.js boop.js
+git commit -m'rawr!'
View
@@ -0,0 +1,99 @@
+var test = require('tap').test;
+var ploy = require('../');
+var path = require('path');
+var spawn = require('child_process').spawn;
+var hyperquest = require('hyperquest');
+var concat = require('concat-stream');
+
+function setup (t) {
+ var ps = spawn(__dirname + '/setup.sh', [ 'multi' ], {
+ cwd: __dirname
+ });
+ ps.on('exit', t.end.bind(t));
+}
+
+function teardown (t) {
+ var ps = spawn(__dirname + '/teardown.sh', [], {
+ cwd: __dirname
+ });
+ ps.stderr.pipe(process.stderr);
+ ps.on('exit', t.end.bind(t));
+ t.on('end', function () {
+ setTimeout(process.exit, 500);
+ });
+}
+
+function commit (cb) {
+ var ps = spawn(__dirname + '/commit.sh', [], {
+ cwd: __dirname + '/repo'
+ });
+ ps.on('exit', cb);
+}
+
+function push (branch, cb) {
+ var args = [
+ 'push',
+ 'http://localhost:' + port + '/_ploy/repo.git',
+ branch
+ ];
+ var ps = spawn('git', args, {
+ cwd: __dirname + '/repo'
+ });
+ ps.on('exit', cb);
+}
+
+var tmpDir = '/tmp/ploy-test/' + Math.random();
+var server = ploy(tmpDir);
+var port;
+
+function pending (n, cb) {
+ return function () { if (--n <= 0) cb() };
+}
+
+test(setup);
+test(function (t) {
+ t.plan(5);
+ server.listen(function () {
+ port = server.address().port;
+ setTimeout(push0, 2000);
+ });
+
+ function push0 () {
+ push('master', function (code) {
+ t.equal(code, 0);
+ var next = pending(2, deploy);
+
+ setTimeout(function () {
+ verify('BEEP\n', 'beep.local', next);
+ verify('BOOP\n', 'boop.local', next);
+ }, 3000);
+ });
+ }
+
+ function push1 () {
+ push('staging', function (code) {
+ t.equal(code, 0);
+ setTimeout(function () {
+ verify('dino\n', 'beep.staging.local');
+ verify('saur\n', 'boop.staging.local');
+ }, 3000);
+ });
+ }
+
+ function deploy () {
+ commit(function (code) {
+ t.equal(code, 0);
+ push1();
+ });
+ }
+
+ function verify (msg, host, cb) {
+ var hq = hyperquest('http://localhost:' + port);
+ hq.setHeader('host', host);
+ hq.pipe(concat(function (err, body) {
+ t.equal(msg, String(body));
+ if (cb) cb();
+ }));
+ }
+});
+test(teardown);

0 comments on commit 575a340

Please sign in to comment.