Skip to content

Commit

Permalink
Merge pull request #168 from screwdriver-cd/queue
Browse files Browse the repository at this point in the history
feat: add queue job config validation schema
  • Loading branch information
r3rastogi authored Aug 7, 2017
2 parents 007639d + d8d50b5 commit f744390
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const datastore = require('./datastore');
const executor = require('./executor');
const queue = require('./queue');
const scm = require('./scm');

module.exports = { datastore, executor, scm };
module.exports = { datastore, executor, queue, scm };
22 changes: 22 additions & 0 deletions plugins/queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const Joi = require('joi');
const executor = require('./executor');
const SCHEMA_EXECUTOR_CONFIG = Joi.object().keys({
name: Joi.string().required(),
options: Joi.object().required()
}).required();
const SCHEMA_START = Joi.object().keys({
buildConfig: executor.start,
executor: SCHEMA_EXECUTOR_CONFIG
}).required();

module.exports = {
/**
* Validates the queue job config generated by the START method in executor-queue
*
* @property start
* @type {Joi}
*/
start: SCHEMA_START
};
11 changes: 11 additions & 0 deletions test/data/queue.start.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
buildConfig:
buildId: 8609
container: node:4
apiUri: http://localhost:8080
token: eyJhbGciOiJIUziIsInR5cCI6IkpXVCJ9.eyJ1c2Vybam9obmpvaG5zb24iLCJzY29wZSI6WyJ1c2VyIl0sImlhdCI6MTQ3MDI2NjAwMywiZXhwIjoxNDcwMzA5MjAzfQ.CHaHW2-0wALpWaS4UTXQmSAn_ekMBml-ENEnGhw-9SE
executor:
name: k8s
options:
kubernetes:
host: kubernetes.default
launchVersion: latest
17 changes: 17 additions & 0 deletions test/plugins/queue.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const assert = require('chai').assert;
const queue = require('../../plugins/queue');
const validate = require('../helper').validate;

describe('executor test', () => {
describe('start', () => {
it('validates the start', () => {
assert.isNull(validate('queue.start.yaml', queue.start).error);
});

it('fails the start for empty yaml', () => {
assert.isNotNull(validate('empty.yaml', queue.start).error);
});
});
});

0 comments on commit f744390

Please sign in to comment.