auto run test, aggiornamento http mock

This commit is contained in:
Enrico Fasoli 2015-04-28 10:11:01 +02:00
parent 50940b4ca2
commit 3a62bd34bc
4 changed files with 20 additions and 19 deletions

View File

@ -14,13 +14,6 @@ before = (done) ->
receive = (f) -> robot.adapter.on 'send', f receive = (f) -> robot.adapter.on 'send', f
after = -> robot.shutdown() after = -> robot.shutdown()
clear = -> robot.adapter.removeAllListeners(); robot.httpListener = -> clear = -> robot.adapter.removeAllListeners(); robot.httpListener = ->
# Intercept hubot's http calls
robot.onHttp = (f) -> robot.httpListener = f
robot.http = (addr) ->
get: ->
(cb) -> robot.httpListener 'GET', addr, cb
post: ->
(cb) -> robot.httpListener 'POST', addr, cb
# Done # Done
done done
robot: robot, user: user, send: send, receive: receive robot: robot, user: user, send: send, receive: receive

View File

@ -38,6 +38,7 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "^2.3.0", "chai": "^2.3.0",
"hubot-mock-adapter": "^1.0.0" "hubot-mock-adapter": "^1.0.0",
"nock": "^1.7.1"
} }
} }

View File

@ -29,18 +29,28 @@ runCmd = (cmd,res,cb) ->
module.exports = (robot) -> module.exports = (robot) ->
robot.respond /aggiornati|scarica (?:gli )?aggiornamenti/i, (res) -> robot.respond /aggiornati|scarica (?:gli )?aggiornamenti/i, (res) ->
runCmd 'git pull && npm install', res runCmd 'git pull && npm install && npm install --dev', res
robot.respond /(?:controlla gli )?aggiornamenti/i, (res) -> robot.respond /(?:controlla gli )?aggiornamenti/i, (res) ->
runCmd 'git fetch && git status', res runCmd 'git fetch && git status', res
robot.respond /(?:installa (?:le )?)dipendenze/i, (res) -> robot.respond /(?:installa (?:le )?)dipendenze/i, (res) ->
runCmd 'npm install', res runCmd 'npm install && npm install --dev', res
# Run tests on boot and report to ADMIN
if process.env.AUTO_RUN_TESTS and process.env.ADMIN_ROOM
dest = room: process.env.ADMIN_ROOM.replace(':','#')
robot.send dest, 'Operazione in corso: npm test'
runCmd 'npm test', null, (err,stdout,stderr) ->
if err
robot.send dest, 'ATTENZIONE: TEST FAILURE\n'+stdout+stderr
else
robot.send dest, 'Test superati con successo:\n'+stdout
robot.on 'githubhook', (data,params) -> robot.on 'githubhook', (data,params) ->
if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE
runCmd 'git pull & npm install', null, -> runCmd 'git pull && npm install && npm install --dev', null, ->
dest = name: params.name, room: params.room.replace(':','#') dest = name: params.name, room: params.room.replace(':','#')
robot.send dest, 'riavvio in 5 SECONDI' robot.send dest, 'riavvio in 5 SECONDI'
reboot = -> reboot = ->
console.log 'AUTO IMPICCAGIONE IN CORSO!' console.log 'AUTO IMPICCAGIONE IN CORSO!'

View File

@ -1,3 +1,4 @@
nock = require 'nock'
expect = require("chai").should() expect = require("chai").should()
Asjon = require '../asjon-testing.coffee' Asjon = require '../asjon-testing.coffee'
@ -14,14 +15,10 @@ describe 'hubot mock', ->
done() done()
it 'should intercept hubot\'s HTTP calls', (done) -> it 'should intercept hubot\'s HTTP calls', (done) ->
asjon.robot.onHttp (method, addr, cb) -> nock('http://ddg.gg').get('/').reply 200, 'nocked'
addr.should.equal 'http://ddg.gg'
method.should.equal 'GET'
cb null, 200, 'mock body'
asjon.robot.http('http://ddg.gg') asjon.robot.http('http://ddg.gg')
.get() (err, res, body) -> .get() (err, res, body) ->
if err then throw err res.statusCode.should.equal 200
res.should.equal 200 body.should.equal 'nocked'
body.should.equal 'mock body'
done() done()