强化 mock test

This commit is contained in:
jysperm
2014-05-30 15:07:41 +08:00
parent 518d5dd0a3
commit 67733766e9
8 changed files with 85 additions and 58 deletions

View File

@@ -2,6 +2,7 @@ child_process = require 'child_process'
express = require 'express'
service = require './service'
plugin = require '../../core/plugin'
{requestAuthenticate} = require '../../core/router/middleware'
@@ -24,5 +25,7 @@ exports.post '/switch', (req, res) ->
$set:
'attribute.plugin.phpfpm.is_enable': false
, ->
service.switch req.account, req.body.enable, ->
plugin.systemOperate (callback) ->
service.switch req.account, req.body.enable, callback
, ->
res.json {}

View File

@@ -6,6 +6,8 @@ async = require 'async'
tmp = require 'tmp'
fs = require 'fs'
plugin = require '../../core/plugin'
mAccount = require '../../core/model/account'
module.exports =
@@ -23,26 +25,28 @@ module.exports =
callback()
switch: (account, is_enable, callback) ->
callbackback = ->
child_process.exec 'sudo service php5-fpm restart', (err) ->
throw err if err
callback()
if is_enable
tmp.file
mode: 0o750
, (err, filepath, fd) ->
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/fpm-pool.conf')).toString(),
account: account
fs.writeSync fd, config_content, 0, 'utf8'
fs.closeSync fd
child_process.exec "sudo cp #{filepath} /etc/php5/fpm/pool.d/#{account.username}.conf", (err) ->
plugin.systemOperate (callback) ->
callbackback = ->
child_process.exec 'sudo service php5-fpm restart', (err) ->
throw err if err
callback()
if is_enable
tmp.file
mode: 0o750
, (err, filepath, fd) ->
config_content = _.template (fs.readFileSync path.join(__dirname, 'template/fpm-pool.conf')).toString(),
account: account
fs.writeSync fd, config_content, 0, 'utf8'
fs.closeSync fd
child_process.exec "sudo cp #{filepath} /etc/php5/fpm/pool.d/#{account.username}.conf", (err) ->
throw err if err
callbackback()
else
child_process.exec "sudo rm /etc/php5/fpm/pool.d/#{account.username}.conf", ->
callbackback()
else
child_process.exec "sudo rm /etc/php5/fpm/pool.d/#{account.username}.conf", ->
callbackback()
, callback
widget: (account, callback) ->
jade.renderFile path.join(__dirname, 'view/widget.jade'), {account: account}, (err, html) ->