Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenpeeters committed Jun 26, 2017
1 parent 9f6bd91 commit 8bd284f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/coffee/compose/lib.test.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
assert = require 'assert'
{transformDependsOnToObject} = require '../../../src/coffee/compose/lib.coffee'
td = require 'testdouble'

spawn = null
transformDependsOnToObject = null
runCmd = null

describe 'Compose lib', ->

afterEach -> td.reset()

beforeEach ->
spawn = td.replace('child_process').spawn
lib = require '../../../src/coffee/compose/lib.coffee'
transformDependsOnToObject = lib.transformDependsOnToObject
runCmd = lib.runCmd

describe 'transformDependsOnToObject', ->

it 'should return null when the argument is falsy', ->
Expand All @@ -21,3 +34,26 @@ describe 'Compose lib', ->
www: condition: 'service_started'
db: condition: 'service_started'
someOther: condition: 'service_started'

describe 'runCmd', ->
it 'should log an error when the command did not run sucessfully', ->
td.when(spawn 'myCmd', {myArgs: 1}, td.matchers.anything()).thenReturn {error: 'some error'}
_console = td.object ['error']
runCmd 'myCmd', {myArgs: 1}, {}, null, null, _console
td.verify _console.error "Error, unable to execute", 'myCmd', {myArgs: 1}, 'some error'

it 'should log and call appropriate callbacks on successful completion', ->
spawned =
stdout: td.object ['on']
stderr: td.object ['on']
on: td.function()
_console = td.object ['log']
callbacks =
stdout: 1
stderr: 2
td.when(spawn 'myCmd', {myArgs: 1}, td.matchers.anything()).thenReturn spawned
runCmd 'myCmd', {myArgs: 1}, {}, callbacks, 'exitCb', _console
td.verify _console.log 'success', 'myCmd', {myArgs: 1}
td.verify spawned.stdout.on 'data', 1
td.verify spawned.stderr.on 'data', 2
td.verify spawned.on 'close', 'exitCb'

0 comments on commit 8bd284f

Please sign in to comment.