Skip to content

Commit

Permalink
different flavour of chaos on each request
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakuan committed Jan 28, 2015
1 parent e255b34 commit 7d538f9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
13 changes: 13 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var express = require('express'),
app = express(),
chaos = require('../index');

app.use(chaos());

app.get('/', function(req, res, next) {
res.send('CHAOS: hello from example, it looks like this request got through');
});

app.listen(3009, function() {
console.log('booted chos example app on 3009');
});
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function _truthy(val) {

// calls a method on a object with the args
// flipped to accept the object last
var _flipFunc = R.curry(function(method, args, obj){
var _flipFunc = R.curry(function(method, args, obj) {
return obj[method].apply(null, args);
});

Expand All @@ -28,12 +28,17 @@ var _handlersForOptions = R.curry(function(handlers, opts) {
// full list of built handlers
var allHandlers = R.map(R.func('factory'), handlers);

// find the relevent handlers for the provided options and build them
// if no options are provided, all handlers are built
// after that, pick a random one and return it
var chaos = R.compose(
// pick the handlers that match the args
var pickFromArgs = R.compose(
_randomElement,
R.ifElse(_truthy, _handlersForOptions(handlers), R.always(allHandlers))
);

var chaos = function(opts) {
console.log('CHAOS: Running in CHAOS MODE. Requests will be delayed, error or worse...');
return function (req, res, next) {
return pickFromArgs(opts).apply(null, arguments);
}
};

module.exports = chaos;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connect-chaos",
"version": "0.0.8",
"version": "0.1.0",
"description": "connect / express middleware that causes chaos",
"main": "index.js",
"scripts": {
Expand Down
9 changes: 0 additions & 9 deletions try.js

This file was deleted.

0 comments on commit 7d538f9

Please sign in to comment.