Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maccyber committed Nov 5, 2016
1 parent a21aa30 commit e503f8c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
15 changes: 7 additions & 8 deletions lib/dockerhub-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ module.exports = (options, callback) => {
http(httpOptions, (err, response, body) => {
if (err) {
return callback(err)
} else if (response.statusCode !== 200) {
return callback(`Callback URL returned: ${body}`)
} else {
const message = {
code: response.statusCode,
response: body,
text: `Callback sent to ${options.callbackUrl}`
}
return callback(null, message)
}
const message = {
code: response.statusCode,
response: body,
text: `Callback successfully sent to ${options.callbackUrl}`
}
return callback(null, message)
})
}

7 changes: 2 additions & 5 deletions lib/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ module.exports = (options, callback) => {
options.state = 'error'
}
const result = err || stderr || stdout
if (result) {
options.description = result.substring(0, 200)
return callback(null, { options: options, result: result })
}
return callback(null, true)
options.description = result.substring(0, 200)
return callback(null, { options: options, result: result })
})
}
2 changes: 1 addition & 1 deletion test/test-dockerhub-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tap.test('dockerhubCallback', (t) => {
if (err) {
throw err
}
t.equal(data.text, `Callback successfully sent to ${options.callbackUrl}`, 'dockerhubCallback ok')
t.equal(data.text, `Callback sent to ${options.callbackUrl}`, 'dockerhubCallback ok')
t.equal(data.response.test, 'ok', 'dockerhubCallback response ok')
t.end()
})
Expand Down
37 changes: 37 additions & 0 deletions test/test-hook-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,40 @@ tap.test('hookAction missing options.script', (t) => {
})
})

tap.test('hookAction script do not exist', (t) => {
const options = {
callbackUrl: 'wrongurl',
script: 'dengalevandrer'
}
hookAction(options, (err) => {
t.match(err, 'does not exist', 'runScript script do not exist ok')
t.end()
})
})

tap.test('hookAction dockerhubCallback fail', (t) => {
const options = {
callbackUrl: 'wrongurl',
script: 'hello.sh'
}
hookAction(options, (err) => {
t.equal(err.message, `Invalid URI "${options.callbackUrl}"`, 'Wrong URL ok')
t.end()
})
})

tap.test('hookAction ok', (t) => {
const options = {
callbackUrl: 'https://maccyber.io/api/test',
script: 'hello.sh'
}
hookAction(options, (err, data) => {
if (err) {
throw err
}
t.equal(data.callback, `Callback sent to ${options.callbackUrl}`, 'hookAction dockerhubCallback ok')
t.equal(data.script, 'Running dummy script\n', 'hookAction script ok')
t.end()
})
})

0 comments on commit e503f8c

Please sign in to comment.