aggiunti altri test per github.coffee e shell.coffee

This commit is contained in:
Enrico Fasoli 2015-04-29 17:09:32 +02:00
parent bc781c7ad0
commit 0595fbc889
3 changed files with 57 additions and 8 deletions

View File

@ -22,6 +22,7 @@ runCmd = (cmd,res,cb) ->
if process.env.TESTING_ASJON if process.env.TESTING_ASJON
# Fingi di eseguire l'operazione # Fingi di eseguire l'operazione
if res? then res.send 'Operazione "completata": '+cmd if res? then res.send 'Operazione "completata": '+cmd
if cb? then cb null,'',''
else cp.exec cmd, (err,stdout,stderr) -> else cp.exec cmd, (err,stdout,stderr) ->
if res? if res?
if err if err
@ -51,7 +52,7 @@ module.exports = (robot) ->
if process.env.AUTO_RUN_TESTS and process.env.ADMIN_ROOM if process.env.AUTO_RUN_TESTS and process.env.ADMIN_ROOM
dest = room: process.env.ADMIN_ROOM.replace(':','#') dest = room: process.env.ADMIN_ROOM.replace(':','#')
robot.send dest, 'Operazione in corso: npm test' robot.send dest, 'Operazione in corso: npm test'
runCmd 'npm test', null, (err,stdout,stderr) -> runCmd 'npm test', dest, (err,stdout,stderr) ->
if err if err
robot.send dest, 'ATTENZIONE: TEST FAILURE\n'+stdout+stderr robot.send dest, 'ATTENZIONE: TEST FAILURE\n'+stdout+stderr
else else
@ -59,11 +60,12 @@ module.exports = (robot) ->
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, -> dest = name: params.name, room: params.room.replace(':','#')
dest = name: params.name, room: params.room.replace(':','#') res = send: (x) -> robot.send dest, x
runCmd 'git pull && npm install', res, ->
robot.send dest, 'riavvio in 5 SECONDI' robot.send dest, 'riavvio in 5 SECONDI'
reboot = -> reboot = -> process.exit 0
console.log 'AUTO IMPICCAGIONE IN CORSO!' unless process.env.TESTING_ASJON
process.exit 0 # Non riavviare durante i test
setTimeout reboot, 5000 setTimeout reboot, 5000

View File

@ -3,6 +3,7 @@ expect = require("chai").should()
Asjon = require '../asjon-testing.coffee' Asjon = require '../asjon-testing.coffee'
asjon = undefined asjon = undefined
githubhook = undefined
describe 'modulo github', -> describe 'modulo github', ->
before (done) -> before (done) ->
@ -11,7 +12,7 @@ describe 'modulo github', ->
asjon = assa asjon = assa
after asjon.after after asjon.after
afterEach asjon.clear afterEach asjon.clear
require('../scripts/github.coffee')(asjon.robot) githubhook = require('../scripts/github.coffee')(asjon.robot)
done() done()
it 'dovrebbe rispondere a "mostra le issues"', (done) -> it 'dovrebbe rispondere a "mostra le issues"', (done) ->
@ -87,3 +88,32 @@ describe 'modulo github', ->
if acc is 2 then done() if acc is 2 then done()
asjon.send 'asjon linkami la issue numero 5' asjon.send 'asjon linkami la issue numero 5'
asjon.send 'asjon linkami issue 456' asjon.send 'asjon linkami issue 456'
it 'dovrebbe rendere disponibile l\'handler del webhook', ->
githubhook.should.not.be.undefined
it 'dovrebbe informare correttamente riguardo gli aggiornamenti', (done) ->
acc = 0
req =
body:
ref: 'refs/heads/dev'
commits: []
params:
room: ':mocha'
user: ':mocha'
res =
send: (code) -> code.should.equal 200
asjon.receive (e,l) ->
if acc is 0
l.join().should.equal 'Branch '+req.body.ref+' aggiornato!\n'
if acc is 1
l.join().should.equal 'Branch '+req.body.ref+' aggiornato!\ntest -> commit'
acc++
if acc is 2 then done()
githubhook req, res
req.body.ref = 'refs/heads/master'
req.body.commits.push
committer:
username: 'test'
message: 'commit'
githubhook req, res

View File

@ -67,3 +67,20 @@ describe 'modulo shell', ->
acc++ acc++
if acc is 2 then done() if acc is 2 then done()
asjon.send 'asjon esegui i test' asjon.send 'asjon esegui i test'
it 'dovrebbe autoriavviarsi in caso di update se richiesto', (done) ->
data = ref: 'refs/heads/master'
params = room: ':mocha', user: ':mocha'
acc = 0
asjon.receive (e,l) ->
if acc is 0
l.join().should.equal 'Operazione in corso: git pull && npm install'
if acc is 1
l.join().should.equal 'Operazione "completata": git pull && npm install'
if acc is 2
l.join().should.equal 'riavvio in 5 SECONDI'
acc++
if acc is 3
done()
process.env.AUTO_KILL_ON_UPDATE = 'true'
asjon.robot.emit 'githubhook', data, params