Files
panic-server/patch.js
Jesse Gibson d38154cb6f Test gun by passing options, Browser constructor automatically begins a test on a new window, added package.json, patch function for options (validation/default values).
Exposed a function named "test" that takes an options object, with things like how many gun requests to fire in total, what data to send, where to put it, what peers to connect to, etc...

Exposed a Browser constructor that opens up a new window and runs the test function with the options provided, returning an interface to the window.

Added a patch function to validate the option input and provide defaults where there aren't any values.
2015-12-17 23:20:57 -07:00

38 lines
649 B
JavaScript

/*globals Gun*/
/*
Expect an object like this:
var thing = {
interval: Number,
peers: Array,
amount: Number,
id: String,
key: String,
path: String,
data: *
};
*/
function patch(opt) {
'use strict';
if (!opt) {
throw new Error('No options provided');
}
if (!opt.id) {
throw new Error('No ID given');
}
var url = location.protocol + '//';
url += location.host;
url += '/gun';
opt.key = opt.key || 'panic/test/';
opt.interval = opt.interval || 20;
opt.peers = opt.peers || [url];
opt.amount = opt.amount || 1000;
opt.path = opt.path || Gun.text.random();
opt.data = opt.data || Gun.text.random();
return opt;
}