Skip to content

Commit

Permalink
allow for fixture overrides on events, fixtures/queue_dw.loadv2.json
Browse files Browse the repository at this point in the history
  • Loading branch information
roaringdev committed Feb 5, 2018
1 parent d0be12f commit 6222536
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 44 deletions.
34 changes: 34 additions & 0 deletions leo-cli-configure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

var path = require('path');
var program = require('commander');
var colors = require('colors');

const utils = require("./lib/utils.js");

const watch = require("node-watch");
const fork = require("child_process").fork;

const generateProfile = require("leo-sdk/lib/generateProfile.js");

program
.version('0.0.1')
.option("-g, --global", "Install Globally")
.option("--region [region]", "Region to run cloudformation")
.usage('<stack> <region> <dir> [options]')
.action(function(stack, region, dir, options) {
if (typeof dir === "object") {
dir = ".";
options = dir;
}

generateProfile(stack, {
region: region
}, dir, (err) => {
console.log("done");
});
})
.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp(colors.red);
}
11 changes: 0 additions & 11 deletions leo-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ program
f();
}
}
if (process.platform === "win32") {
var rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});

rl.on("SIGINT", function() {
process.emit("SIGINT");
});
}
console.log("setting up signint");
process.on('SIGINT', () => {
if (child) {
console.log("closing child process. Ctrl-c again to cancel test");
Expand Down
1 change: 1 addition & 0 deletions leo-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ program
.command('run [directory]', "Run your lambda")
.command('create [type] [directory]', "Create a new leo system, bot, resource, or microservice")
.command('cron [id] [runner]', "Runs a cron handler for bot id")
.command('configure [leo_bus_stack] [dir]', "Download Runs a cron handler for bot id")
.parse(process.argv);
33 changes: 0 additions & 33 deletions lib/leo-bot-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,6 @@ module.exports = function(argv, callback) {
}



//let's figure out what fixtures they may have
let overrideStreams = {};
let fixtureDir = path.resolve(rootDir, "fixtures");
if (fs.existsSync(fixtureDir)) {
fs.readdirSync(fixtureDir).forEach(file => {
overrideStreams[path.basename(file).replace("queue_", "").replace(".js", "").toLowerCase()] = require(path.resolve(fixtureDir, file));
});
}
let overrideStreamKeys = Object.keys(overrideStreams);
if (overrideStreamKeys.length) {

/*@TODO Override the fromLeo*/
// let original = ls.fromLeo;
// ls.fromLeo = function(id, outQueue, opts) {
// if (overrideStreamKeys.indexOf(outQueue.toLowerCase()) !== -1) {
// var pass = new PassThrough({
// highWaterMark: opts.buffer,
// objectMode: true
// });
// overrideStreams[outQueue.toLowerCase()].forEach(event => {
// pass.write({
// payload: event
// });
// });
// return pass;
// } else {
// return original.apply(arguments);
// }
// }
}


// var cloudformation = new aws.CloudFormation({
// region: config.aws.region
// });
Expand Down
46 changes: 46 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
var fs = require('fs');
var path = require('path');
var moment = require("moment");
const PassThrough = require("stream").PassThrough;

//need to remove from argv because this is a fork
let argv = process.argv.slice(2);
let utils = require("./utils.js");



//let's figure out what fixtures they may have
let overrideStreams = {};
let fixtureDir = path.resolve(process.cwd(), "fixtures");
if (fs.existsSync(fixtureDir)) {
fs.readdirSync(fixtureDir).forEach(file => {
overrideStreams[path.basename(file).replace("queue_", "").replace(".js", "").toLowerCase()] = require(path.resolve(fixtureDir, file));
});
}
let overrideStreamKeys = Object.keys(overrideStreams);
if (overrideStreamKeys.length) {
let dirs = utils.findParentFiles(process.cwd(), "node_modules");

for (var i = 0; i < dirs.length; i++) {
if (fs.existsSync(path.resolve(dirs[i], "leo-sdk"))) {
require(path.resolve(dirs[i], "leo-sdk/lib/stream/leo-stream.js")).visit = function(ls) {
console.log("I GOT VISITED");
let original = ls.fromLeo;
ls.fromLeo = function(id, outQueue, opts) {
if (overrideStreamKeys.indexOf(outQueue.toLowerCase()) !== -1) {
var pass = new PassThrough({
highWaterMark: opts.buffer,
objectMode: true
});
overrideStreams[outQueue.toLowerCase()].forEach(event => {
pass.write({
payload: event
});
});
pass.end();
return pass;
} else {
return original.apply(arguments);
}
}
};
break;
}
}
}



require("./leo-bot-run.js")(argv, (err, module) => {
module.handler(module.event, createContext({}, module.config), (err, data) => {
Expand Down

0 comments on commit 6222536

Please sign in to comment.