Permalink
Browse files

failing test to run the install hooks

  • Loading branch information...
1 parent ad7ae40 commit 77e4aaacc77f6e16da1d7e0008254b892a167ca4 @substack committed Apr 3, 2013
View
5 test/commit/install.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+git checkout -b staging
+echo >> server.js
+git add server.js
+git commit -m'nop'
View
91 test/install.js
@@ -0,0 +1,91 @@
+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', [ 'install' ], {
+ 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/deploy.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;
+
+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);
+ setTimeout(function () {
+ verify('one\ntwo\n', 'local', deploy);
+ }, 3000);
+ });
+ }
+
+ function push1 () {
+ push('staging', function (code) {
+ t.equal(code, 0);
+ setTimeout(function () {
+ verify('one\ntwo\n', '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);
View
2 test/source/install/install.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo two >> file.txt
View
9 test/source/install/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "ploy-test-repo",
+ "version": "0.0.0",
+ "scripts": {
+ "pre-install": "./pre.sh",
+ "install": "./install.sh",
+ "start": "node server.js"
+ }
+}
View
2 test/source/install/pre.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo one >> file.txt
View
10 test/source/install/server.js
@@ -0,0 +1,10 @@
+var http = require('http');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/file.txt');
+
+var server = http.createServer(function (req, res) {
+ res.end(src);
+});
+
+var port = process.argv[2] || process.env.PORT;
+server.listen(port);

0 comments on commit 77e4aaa

Please sign in to comment.