-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
193 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const config = require('../config') | ||
|
||
tap.equal(config.port, 3000, 'Default server port ok') | ||
tap.equal(config.route, '/api', 'Default route ok') | ||
tap.equal(config.token, 'abc123', 'Default token ok') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const dockerhubCallback = require('../lib/dockerhub-callback') | ||
|
||
tap.test('dockerhubCallback missing options', (t) => { | ||
const options = false | ||
dockerhubCallback(options, (err) => { | ||
t.equal(err.message, 'Missing required input: options', 'Missing options ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('dockerhubCallback missing options.callbackUrl', (t) => { | ||
const options = {} | ||
dockerhubCallback(options, (err) => { | ||
t.equal(err.message, 'Missing required input: options.callbackUrl', 'Missing options.callbackUrl ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('dockerhubCallback invalid URI', (t) => { | ||
const options = { | ||
callbackUrl: 'wrongurl' | ||
} | ||
dockerhubCallback(options, (err) => { | ||
t.equal(err.message, `Invalid URI "${options.callbackUrl}"`, 'Wrong URL ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('dockerhubCallback', (t) => { | ||
const options = { | ||
callbackUrl: 'https://maccyber.io/api/test' | ||
} | ||
dockerhubCallback(options, (err, data) => { | ||
if (err) { | ||
throw err | ||
} | ||
t.equal(data.text, `Callback sent to ${options.callbackUrl}`, 'dockerhubCallback ok') | ||
t.equal(data.response.test, 'ok', 'dockerhubCallback response ok') | ||
t.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const Hapi = require('hapi') | ||
const config = require('../config') | ||
const routes = require('../routes') | ||
|
||
const server = new Hapi.Server() | ||
server.connection() | ||
server.route(routes) | ||
|
||
tap.test('GET /', (t) => { | ||
server.inject('/', (res) => { | ||
t.equal(res.statusCode, 200, 'Status code ok') | ||
t.equal(res.result.message, '(Nothing but) Flowers', 'Message ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('Not found', (t) => { | ||
const route = `/wrongroute` | ||
server.inject(route, (res) => { | ||
t.equal(res.statusCode, 404, '404 returned OK') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('Invalid token or dockerhub JSON', (t) => { | ||
const options = { | ||
method: 'POST', | ||
url: `${config.route}/${config.token}`, | ||
payload: {} | ||
} | ||
server.inject(options, (res) => { | ||
t.equal(res.statusCode, 400, 'Invalid token or dockerhub JSON ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('does not exist in scripts/index.js', (t) => { | ||
const file = require('./data/dockerhub.json') | ||
file.repository.name = 'wrong' | ||
const options = { | ||
method: 'POST', | ||
url: `${config.route}/${config.token}`, | ||
payload: file | ||
} | ||
server.inject(options, (res) => { | ||
t.equal(res.statusCode, 400, 'Repo is not configured config ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('Valid dockerhub JSON', (t) => { | ||
const file = require('./data/dockerhub.json') | ||
file.repository.name = 'testhook' | ||
const options = { | ||
method: 'POST', | ||
url: `${config.route}/${config.token}`, | ||
payload: file | ||
} | ||
server.inject(options, (res) => { | ||
t.equal(res.statusCode, 204, 'Valid dockerhub JSON ok') | ||
t.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const Hapi = require('hapi') | ||
const runScript = require('../lib/run-script') | ||
const server = new Hapi.Server() | ||
|
||
tap.test('runScript missing options', (t) => { | ||
const options = false | ||
const result = runScript(options) | ||
t.equal(result.message, 'Missing required input: options', 'runScript missing options ok') | ||
t.end() | ||
}) | ||
|
||
tap.test('runScript missing options.request', (t) => { | ||
const options = {} | ||
const result = runScript(options) | ||
t.equal(result.message, 'Missing required input: options.request', 'runScript missing options.request ok') | ||
t.end() | ||
}) | ||
|
||
tap.test('runScript missing options.script', (t) => { | ||
const options = { | ||
request: server | ||
} | ||
const result = runScript(options) | ||
t.equal(result.message, 'Missing required input: options.script', 'runScript missing options.script ok') | ||
t.end() | ||
}) | ||
|
||
tap.test('runScript script do not exist', (t) => { | ||
const options = { | ||
request: server, | ||
script: 'dengalevandrer' | ||
} | ||
const result = runScript(options) | ||
t.match(result.message, 'does not exist', 'runScript script do not exist ok') | ||
t.end() | ||
}) |
Oops, something went wrong.