Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update cli handling to use latest bagofholding, first go at updating …

…tests to use busterjs.
  • Loading branch information...
commit 6f82250c7bacbd2f36e69e258ea1de937893848d 1 parent 9b82277
@cliffano authored
View
16 conf/commands.json
@@ -0,0 +1,16 @@
+{
+ "commands": {
+ "init": {
+ "desc": "Create sample template files\nUsage: datagen init"
+ },
+ "gen": {
+ "desc": "Generate data file\nUsage: datagen [-i/--gen-id <genId>] [-s/--num-segments <numSegments>] [-w/--num-workers <numWorkers>] [-o/--out-file <outFile>] gen",
+ "options": [
+ { "arg": "-i, --gen-id <genId>", "desc": "An ID unique to the current data generation, used by all worker processes | defaut: datagen process PID" },
+ { "arg": "-s, --num-segments <numSegments>", "desc": "How many segments in a data file | default: 1" },
+ { "arg": "-w, --num-workers <numWorkers>", "desc": "How many worker processes, each worker creates a data file | default: 1" },
+ { "arg": "-o, --out-file <outFile>", "desc": "Generated data file name, postfixed with worker ID | default: 'data'" }
+ ]
+ }
+ }
+}
View
45 lib/cli.js
@@ -1,40 +1,27 @@
-var _ = require('underscore'),
- bag = require('bagofholding'),
- fs = require('fs'),
- p = require('path'),
- datagen = require('./datagen');
+var bag = require('bagofholding'),
+ DataGen = require('./datagen');
+
+function _init() {
+ new DataGen().init(bag.cli.exit);
+}
+
+function _generate(args) {
+ new DataGen().generate(args.genId, parseInt(args.numSegments, 10), parseInt(args.numWorkers, 10), args.outFile, bag.cli.exit);
+}
/**
- * Execute datagen using header, segment, and footer files in the current directory.
+ * Execute DataGen CLI.
*/
function exec() {
- function _init() {
- new datagen().init(bag.cli.exit);
- }
-
- function _generate(args) {
- new datagen().generate(args.genId, args.numSegments, args.numWorkers, args.outFile, bag.cli.exit);
- }
-
- var commands = {
- init: {
- desc: 'Create example template files',
- action: _init
- },
- gen: {
- desc: 'Generate data file',
- options: [
- { arg: '-i, --gen-id <genId>', desc: 'An ID unique to the current data generation, used by all worker processes | defaut: datagen process PID' },
- { arg: '-s, --num-segments <numSegments>', desc: 'How many segments in a data file | default: 1', action: parseInt },
- { arg: '-w, --num-workers <numWorkers>', desc: 'How many worker processes, each worker creates a data file | default: 1', action: parseInt },
- { arg: '-o, --out-file <outFile>', desc: 'Generated data file name, postfixed with worker ID | default: \'data\'' }
- ],
- action: _generate
+ var actions = {
+ commands: {
+ init: { action: _init },
+ gen: { action: _generate }
}
};
- bag.cli.parse(commands, __dirname);
+ bag.cli.command(__dirname, actions);
}
exports.exec = exec;
View
4 lib/functions.js
@@ -1,7 +1,7 @@
var dateFormat = require('dateformat'),
faker = require('Faker'),
- nonsense = require('Nonsense'),
- ns = new nonsense();
+ Nonsense = require('Nonsense'),
+ ns = new Nonsense();
/**
* Template function to generate a random integer.
View
16 package.json
@@ -31,17 +31,15 @@
"test": "./test"
},
"dependencies": {
- "bagofholding": "0.0.12",
- "dateformat": "1.0.2-1.2.3",
- "Faker": "0.1.3",
- "ncp": "0.2.6",
+ "bagofholding": "0.1.2",
+ "dateformat": "1.0.4-1.2.3",
+ "Faker": "0.5.6",
+ "ncp": "0.4.0",
"Nonsense": "0.1.2",
- "underscore": "1.3.3"
+ "underscore": "1.4.4"
},
"devDependencies": {
- "mocha": "1.3.2",
- "sandboxed-module": "0.1.3",
- "should": "1.1.0"
+ "buster": "0.6.12"
},
"scripts": {},
"engines": {
@@ -53,4 +51,4 @@
"url": "http://github.com/cliffano/datagen/raw/master/LICENSE"
}
]
-}
+}
View
3  test/cli.js
@@ -1,3 +1,4 @@
+/*
var bag = require('bagofholding'),
sandbox = require('sandboxed-module'),
should = require('should'),
@@ -84,4 +85,4 @@ describe('cli', function () {
});
});
});
-
+*/
View
3  test/datagen.js
@@ -1,3 +1,4 @@
+/*
var bag = require('bagofholding'),
_jscov = require('../lib/datagen'),
sandbox = require('sandboxed-module'),
@@ -96,4 +97,4 @@ describe('datagen', function () {
});
});
});
-
+*/
View
374 test/functions.js
@@ -1,233 +1,181 @@
var _ = require('underscore'),
- bag = require('bagofholding'),
- sandbox = require('sandboxed-module'),
- should = require('should'),
- checks, mocks,
- functions;
-
-describe('functions', function () {
-
- function create(checks, mocks) {
- return sandbox.require('../lib/functions', {
- requires: mocks ? mocks.requires : {},
- globals: {}
+ buster = require('buster'),
+ functions = require('../lib/functions');
+
+buster.testCase('functions - integer', {
+ 'should evaluate integer function when it has no argument': function (done) {
+ functions.integer(function (data) {
+ assert.isNumber(data);
+ assert.isTrue(!data.toString().match(/.+\..+/));
+ done();
+ });
+ },
+ 'should evaluate ranged integer function when it has min max arguments': function (done) {
+ functions.integer(100, 200, function (data) {
+ assert.isNumber(data);
+ assert.isTrue(!data.toString().match(/.+\..+/));
+ assert.isTrue(data >= 100);
+ assert.isTrue(data <= 200);
+ done();
+ });
+ },
+ 'should evaluate identical integer function when it has identical min max arguments': function (done) {
+ functions.integer(100, 100, function (data) {
+ assert.isNumber(data);
+ assert.isTrue(!data.toString().match(/.+\..+/));
+ assert.equals(data, 100);
+ done();
});
}
+});
- beforeEach(function () {
- checks = {};
- mocks = {};
- functions = require('../lib/functions');
- });
-
- describe('integer', function () {
-
- it('should evaluate integer function when it has no argument', function (done) {
- functions.integer(function (data) {
- checks.data = data;
- done();
- });
- (_.isNaN(checks.data)).should.equal(false);
- checks.data.should.not.match(/.+\..+/);
- });
-
- it('should evaluate ranged integer function when it has min max arguments', function (done) {
- functions.integer(100, 200, function (data) {
- checks.data = data;
- done();
- });
- (_.isNaN(checks.data)).should.equal(false);
- checks.data.should.not.match(/.+\..+/);
- checks.data.should.be.within(100, 200);
- });
-
- it('should evaluate identical integer function when it has identical min max arguments', function (done) {
- functions.integer(100, 100, function (data) {
- checks.data = data;
- done();
- });
- (_.isNaN(checks.data)).should.equal(false);
- checks.data.should.not.match(/.+\..+/);
- checks.data.should.equal(100);
- });
- });
-
- describe('float', function () {
-
- it('should evaluate float function when it has no argument', function (done) {
- functions.float(function (data) {
- checks.data = data;
- done();
- });
- (_.isNaN(checks.data)).should.equal(false);
- checks.data.should.match(/.+\..+/);
- });
-
- it('should evaluate ranged float function when it has min max arguments', function (done) {
- functions.float(100.0, 200.0, function (data) {
- checks.data = data;
- done();
- });
- (_.isNaN(checks.data)).should.equal(false);
- checks.data.should.match(/.+\..+/);
- checks.data.should.be.within(100.0, 200.0);
- });
-
- it('should evaluate identical float function when it has identical min max arguments', function (done) {
- functions.float(567.89, 567.89, function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.match(/.+\..+/);
- checks.data.should.equal(567.89);
- });
- });
-
- describe('date', function () {
-
- it('should evaluate date function with ISO format when it has no argument', function (done) {
- functions.date(function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
- });
-
- it('should evaluate date function with custom format when it has format argument', function (done) {
- functions.date('yyyy/mm/dd', function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
- });
-
- it('should evaluate date function with default format and ranged date when it has min max arguments and no format argument', function (done) {
- functions.date(1998, 2000, function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
- parseInt(checks.data.match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
- });
-
- it('should evaluate date function with custom format and ranged date when it has min max format arguments', function (done) {
- functions.date('yyyy/mm/dd', 1998, 2000, function (data) {
- checks.data = data;
- done();
- });
- checks.data.should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
- parseInt(checks.data.match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
- });
- });
-
- describe('select', function () {
-
- it('should evaluate select function when it has arguments', function (done) {
- functions.select('aaa', 'bbb', 'ccc', function (data) {
- checks.data = data;
- done();
- });
- ['aaa','bbb','ccc'].indexOf(checks.data).should.be.within(0, 2);
- });
-
- it('should evaluate identical select function when it has only 1 argument', function (done) {
- functions.select('aaa', function (data) {
- checks.data = data;
- done();
- });
- ['aaa'].indexOf(checks.data).should.equal(0);
+buster.testCase('functions - float', {
+ 'should evaluate float function when it has no argument': function (done) {
+ functions.float(function (data) {
+ assert.isNumber(data);
+ assert.isTrue(data.toString().match(/.+\..+/).length > 0);
+ done();
+ });
+ },
+ 'should evaluate ranged float function when it has min max arguments': function (done) {
+ functions.float(100.0, 200.0, function (data) {
+ assert.isNumber(data);
+ assert.isTrue(data.toString().match(/.+\..+/).length > 0);
+ assert.isTrue(data >= 100.0);
+ assert.isTrue(data <= 200.0);
+ done();
+ });
+ },
+ 'should evaluate identical float function when it has identical min max arguments': function (done) {
+ functions.float(567.89, 567.89, function (data) {
+ assert.isNumber(data);
+ assert.isTrue(data.toString().match(/.+\..+/).length > 0);
+ assert.equals(data, 567.89);
+ done();
});
+ }
+});
- it('should evaluate to empty when select function has no argument', function (done) {
- functions.select(function (data) {
- checks.data = data;
- done();
- });
- ['aaa','bbb','ccc'].indexOf(checks.data).should.equal(-1);
+buster.testCase('functions - date', {
+ 'should evaluate date function with ISO format when it has no argument': function (done) {
+ functions.date(function (data) {
+ assert.isTrue(data.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/).length > 0);
+ done();
+ });
+ },
+ 'should evaluate date function with custom format when it has format argument': function (done) {
+ functions.date('yyyy/mm/dd', function (data) {
+ assert.isTrue(data.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/).length > 0);
+ done();
+ });
+ },
+ 'should evaluate date function with default format and ranged date when it has min max arguments and no format argument': function (done) {
+ functions.date(1998, 2000, function (data) {
+ assert.isTrue(data.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/).length > 0);
+ var year = parseInt(data.match(/^[0-9]{4}/), 10);
+ assert.isTrue(year >= 1998 && year <= 1999);
+ done();
+ });
+ },
+ 'should evaluate date function with custom format and ranged date when it has min max format arguments': function (done) {
+ functions.date('yyyy/mm/dd', 1998, 2000, function (data) {
+ assert.isTrue(data.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/).length > 0);
+ var year = parseInt(data.match(/^[0-9]{4}/), 10);
+ assert.isTrue(year >= 1998 && year <= 1999);
+ done();
});
- });
-
- describe('word', function () {
+ }
+});
- it('should evaluate a single word when word function has no argument', function (done) {
- functions.word(function (data) {
- checks.data = data;
- done();
- });
- (_.isString(checks.data)).should.equal(true);
- checks.data.should.match(/[a-zA-Z]+/);
+buster.testCase('functions - select', {
+ 'should evaluate select function when it has arguments': function (done) {
+ functions.select('aaa', 'bbb', 'ccc', function (data) {
+ var pos = ['aaa','bbb','ccc'].indexOf(data);
+ assert.isTrue(pos >= 0 && pos <= 2);
+ done();
+ });
+ },
+ 'should evaluate identical select function when it has only 1 argument': function (done) {
+ functions.select('aaa', function (data) {
+ var pos = ['aaa'].indexOf(data);
+ assert.equals(pos, 0);
+ done();
+ });
+ },
+ 'should evaluate to empty when select function has no argument': function (done) {
+ functions.select(function (data) {
+ var pos = ['aaa','bbb','ccc'].indexOf(data);
+ assert.equals(pos, -1);
+ done();
});
+ }
+});
- it('should evaluate multiple words when word function has an argument', function (done) {
- functions.word(5, function (data) {
- checks.data = data;
- done();
- });
- function _check(word) {
- (_.isString(word)).should.equal(true);
- word.should.match(/[a-zA-Z]+/);
- }
- var words = checks.data.split(' ');
- words.length.should.equal(5);
- words.forEach(_check);
- });
- });
+buster.testCase('functions - word', {
+ 'should evaluate a single word when word function has no argument': function (done) {
+ functions.word(function (data) {
+ assert.isString(data);
+ assert.isTrue(data.match(/[a-zA-Z]+/).length > 0);
+ done();
+ });
+ },
+ 'should evaluate multiple words when word function has an argument': function (done) {
+ functions.word(5, function (data) {
+ var words = data.split(' ');
+ assert.equals(words.length, 5);
+ words.forEach(function (word) {
+ assert.isString(word);
+ assert.isTrue(word.match(/[a-zA-Z]+/).length > 0);
+ });
+ done();
+ });
+ }
+});
- describe('firstName', function () {
+buster.testCase('functions - firstName', {
- it('should evaluate first name function', function (done) {
- functions.first_name(function (data) {
- checks.data = data;
- done();
- });
- (_.isString(checks.data)).should.equal(true);
- (checks.data.match(/[a-zA-Z]+/) !== null).should.equal(true);
+ 'should evaluate first name function': function (done) {
+ functions.first_name(function (data) {
+ assert.isString(data);
+ assert.isTrue(data.toString().match(/[a-zA-Z]+/).length > 0);
+ done();
});
- });
-
- describe('lastName', function () {
+ }
+});
- it('should evaluate last name function', function (done) {
- functions.last_name(function (data) {
- checks.data = data;
- done();
- });
- (_.isString(checks.data)).should.equal(true);
- checks.data.should.match(/[a-zA-Z]+/);
+buster.testCase('functions - lastName', {
+ 'should evaluate last name function': function (done) {
+ functions.last_name(function (data) {
+ assert.isString(data);
+ assert.isTrue(data.toString().match(/[a-zA-Z]+/).length > 0);
+ done();
});
- });
-
- describe('email', function () {
+ }
+});
- it('should evaluate email function', function (done) {
- functions.email(function (data) {
- checks.data = data;
- done();
- });
- (_.isString(checks.data)).should.equal(true);
- checks.data.should.match(/[a-zA-Z]+/);
+buster.testCase('functions - email', {
+ 'should evaluate email function': function (done) {
+ functions.email(function (data) {
+ assert.isString(data);
+ assert.isTrue(data.toString().match(/[a-zA-Z]+/).length > 0);
+ done();
});
- });
-
- describe('phone', function () {
+ }
+});
- it('should evaluate phone function with default format when format is not specified', function (done) {
- functions.phone(function (data) {
- checks.data = data;
- done();
- });
- (_.isString(checks.data)).should.equal(true);
- checks.data.should.match(/[0-9]{4} [0-9]{4}/);
+buster.testCase('functions - phone', {
+ 'should evaluate phone function with default format when format is not specified': function (done) {
+ functions.phone(function (data) {
+ assert.isString(data);
+ assert.isTrue(data.toString().match(/[0-9]{4} [0-9]{4}/).length > 0);
+ done();
});
-
- it('should evaluate phone function with custom format when format is specified', function (done) {
- functions.phone('(###) ########', function (data) {
- checks.data = data;
- done();
- });
- (_.isString(checks.data)).should.equal(true);
- checks.data.should.match(/\([0-9]{3}\) [0-9]{8}/);
+ },
+ 'should evaluate phone function with custom format when format is specified': function (done) {
+ functions.phone('(###) ########', function (data) {
+ assert.isString(data);
+ assert.isTrue(data.toString().match(/\([0-9]{3}\) [0-9]{8}/).length > 0);
+ done();
});
- });
-});
-
+ }
+});
View
3  test/worker.js
@@ -1,3 +1,4 @@
+/*
var _ = require('underscore'),
bag = require('bagofholding'),
sandbox = require('sandboxed-module'),
@@ -329,4 +330,4 @@ describe('worker', function () {
});
});
});
-
+*/
Please sign in to comment.
Something went wrong with that request. Please try again.