From 0f555a7c30c3f2d151b75d620f5341984f171782 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 27 May 2018 17:00:31 +0300 Subject: [PATCH] test default and custom prefix (#124) --- test/custom-test.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/custom-test.js b/test/custom-test.js index 4deb598..5609320 100644 --- a/test/custom-test.js +++ b/test/custom-test.js @@ -5,6 +5,50 @@ var levelup = require('levelup') module.exports = function (leveljs, test, testCommon) { test('setUp', testCommon.setUp) + test('default prefix', function (t) { + var location = testCommon.location() + var db = leveljs(location) + + t.is(db.location, location, 'instance has location property') + t.is(db.prefix, 'level-js-', 'instance has prefix property') + + db.open(function (err) { + t.notOk(err, 'no open error') + + var idb = db.db + var databaseName = idb.name + var storeNames = idb.objectStoreNames + + t.is(databaseName, 'level-js-' + location, 'database name is prefixed') + t.is(storeNames.length, 1, 'created 1 object store') + t.is(storeNames.item(0), location, 'object store name equals location') + + db.close(t.end.bind(t)) + }) + }) + + test('custom prefix', function (t) { + var location = testCommon.location() + var db = leveljs(location, { prefix: 'custom-' }) + + t.is(db.location, location, 'instance has location property') + t.is(db.prefix, 'custom-', 'instance has prefix property') + + db.open(function (err) { + t.notOk(err, 'no open error') + + var idb = db.db + var databaseName = idb.name + var storeNames = idb.objectStoreNames + + t.is(databaseName, 'custom-' + location, 'database name is prefixed') + t.is(storeNames.length, 1, 'created 1 object store') + t.is(storeNames.item(0), location, 'object store name equals location') + + db.close(t.end.bind(t)) + }) + }) + test('buffer value', function (t) { var level = leveljs(testCommon.location()) level.open(function (err) {