Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
mock-couch
Advanced tools
Mock a CouchDB server for your unit tests.
Mock Couch will create an HTTP server that emulates the responses of a real CouchDB server. Since it is an actual HTTP server, no matter if you use libraries like cradle and nano, your code should work out of the box.
Mock Couch emit events, so you can listen to them to see the result of your test.
npm install --save-dev mock-couch
_all_docs
must return { key : thekey, error : "not_found" }
for each missing key_bulk_docs
didn't converted the functions of the passed design docs.instance_start_time
(Credits to @Dainis)addDB
multiple times. (Credits to @Troy Cochran)_sum
and _count
reduce functions._uuids
(Credits to @watchforstock)_changes
(Credits to @conor-mac-aoidh)key
on views._design/
document to use them. Read more about them here.addDoc
method to add a document from the node.js side. Contrary to adding a document with a PUT, this is sync and allows you to specify the _rev
Visit the Mock Couch website.
mock_couch
object has a databases
public property, to examine how the databases are in any moment._all_docs
, including:
include_docs=true
descending=true
startkey
endkey
_all_docs
with POST to specify the desired keys_all_dbs
_uuids
http://localhost:5984/database/_design/myviews/_view/someview/
)_bulk_docs
multiple documents_deleted
memberKeep in mind that Mock Couch is not attempting to fully implement CouchDB, but only the features necessary for unit testing CouchDB based apps.
However, if there is a feature you need for your tests, feel free to add a feature request in the issues section!
Here is an example:
var mockCouch = require('mock-couch');
// myfun is the function that we want to test.
// It uses couchdb, either by using cradle, nano, or direct http requests
// This function takes an object as parameter, maybe runs some validations
// and if everything is ok, then save it on couchdb.
var myfun = require('somefunc');
describe('myfun', function() {
beforeEach(function() {
// Starting the server
var couchdb = mockCouch.createServer();
// Make sure you are either executing this test under a machine that does not have couchdb installed/enabled,
// or that you are using a different port!
// (which may require that you are able to specify the couchdb port on the function you are about to test)
couchdb.listen(5984);
// This creates a db for Mock Couch. The db is nothing but an array of objects.
// If we provide an object with an _id property, it will use it. Otherwise, it will create a random one.
couchdb.addDB('people', [ { name : 'one name', lastname : 'one lastname' }, { _id : '4568797890', name : 'second name', lastname : 'other lastname' } ]);
});
// Here is the test
it('must add a person to couchdb', function(done) {
// Now we add a listener that is expecting the data we are about to send.
couchdb.on('POST', function(data) {
expect(data.doc.name).toBe('reimu');
expect(data.doc.lastname).toBe('hakurei');
done();
});
// And here we are finally calling the function
myfun({ name : 'reimu', lastname : 'hakurei' });
});
});
If your testing requires the frequent setup and teardown of the mock server, it may be beneficial to prevent keep-alive connections. The server will always return a Connection: close
header if constructed with a keepAlive
option set to false
.
var couchdb = mockCouch.createServer({ keepAlive: false });
In this moment I think it could be considered beta; I don't expect any breaking changes.
MIT license
Your feedback, pull requests, etc are welcomed! :)
FAQs
An http server pretending to be couchdb, for unit testing.
The npm package mock-couch receives a total of 52 weekly downloads. As such, mock-couch popularity was classified as not popular.
We found that mock-couch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.