Skip to content

Instantly share code, notes, and snippets.

@bahamas10
Created May 14, 2014 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bahamas10/98bf6fc910c8e2aef223 to your computer and use it in GitHub Desktop.
Save bahamas10/98bf6fc910c8e2aef223 to your computer and use it in GitHub Desktop.
mock node-manta

replace

var manta = require('manta');

with

var manta = require('./mock-manta');

note that not all functions have been mapped, and this may not work for every case

$ node test.js 
client.createWriteStream worked
client.createReadStream worked
client.put worked
client.get worked
var fs = require('fs');
module.exports.createClient = createClient;
function createClient() {
return new Client();
}
function Client() {
}
function noop(a, b, c) {
if (typeof a === 'function')
c = a;
if (typeof b === 'function')
c = b;
if (typeof c === 'function')
process.nextTick(c);
}
Client.prototype.mkdir = noop;
Client.prototype.mkdirp = noop;
Client.prototype.put = function put(path, stream, opts, cb) {
if (typeof opts === 'function')
cb = opts;
var devnull = fs.createWriteStream('/dev/null');
stream.pipe(devnull);
stream.on('end', function() {
if (cb)
cb();
});
};
Client.prototype.createWriteStream = function createWriteStream(path, opts) {
return fs.createWriteStream('/dev/null');
};
Client.prototype.get = function get(path, cb) {
process.nextTick(function() {
cb(null, fs.createReadStream('/dev/null'));
});
};
Client.prototype.createReadStream = function createReadStream(path, opts) {
return fs.createReadStream('/dev/null');
};
var fs = require('fs');
var manta = require('./mock-manta');
var client = manta.createClient();
var opts = {};
var stream = fs.createReadStream('/dev/null');
client.put('/jill/stor/hello_world.txt', stream, opts, function (err) {
if (err)
throw err;
console.log('client.put worked');
});
var ws = client.createWriteStream('/jill/stor/hello_world.txt', opts);
console.log('client.createWriteStream worked');
ws.write('hello');
ws.end('goodbye');
client.get('/jill/stor/hello_world.txt', function (err, stream) {
if (err)
throw err;
stream.setEncoding('utf8');
stream.on('data', function (chunk) {
console.log(chunk);
});
stream.on('end', function () {
console.log('client.get worked');
});
});
var stream = client.createReadStream('/jill/stor/hello_world.txt');
stream.pipe(process.stdout);
console.log('client.createReadStream worked');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment