|
| 1 | +/* eslint-env mocha */ |
| 2 | +const expect = require('chai').expect |
| 3 | +const ram = require('random-access-memory') |
| 4 | +const hypergraph = require('../index') |
| 5 | +const constants = require('../lib/constants') |
| 6 | + |
| 7 | +function ramStore (filename) { |
| 8 | + // filename will be one of: data, bitfield, tree, signatures, key, secret_key |
| 9 | + // the data file will contain all your data concattenated. |
| 10 | + // just store all files in ram by returning a random-access-memory instance |
| 11 | + return ram() |
| 12 | +} |
| 13 | + |
| 14 | +describe('hypergraph', function () { |
| 15 | + let db |
| 16 | + context('when newly created it adds metadata to db', () => { |
| 17 | + it('includes graph version', (done) => { |
| 18 | + db = hypergraph(ramStore) |
| 19 | + db.on('ready', () => { |
| 20 | + db.db.get('@version', (err, node) => { |
| 21 | + expect(err).to.not.be.a('error') |
| 22 | + expect(node[0].value.toString()).to.match(/\d+.\d+.\d+.*/) |
| 23 | + done() |
| 24 | + }) |
| 25 | + }) |
| 26 | + }) |
| 27 | + it('includes index type (default)', (done) => { |
| 28 | + db = hypergraph(ramStore) |
| 29 | + db.on('ready', () => { |
| 30 | + db.db.get('@index', (err, node) => { |
| 31 | + expect(err).to.not.be.a('error') |
| 32 | + expect(node[0].value.toString()).to.eql('hex') |
| 33 | + done() |
| 34 | + }) |
| 35 | + }) |
| 36 | + }) |
| 37 | + it('includes index type (option.index = tri)', (done) => { |
| 38 | + db = hypergraph(ramStore, { index: 'tri' }) |
| 39 | + db.on('ready', () => { |
| 40 | + db.db.get('@index', (err, node) => { |
| 41 | + expect(err).to.not.be.a('error') |
| 42 | + expect(node[0].value.toString()).to.eql('tri') |
| 43 | + done() |
| 44 | + }) |
| 45 | + }) |
| 46 | + }) |
| 47 | + it('includes name (default)', (done) => { |
| 48 | + db = hypergraph(ramStore) |
| 49 | + db.on('ready', () => { |
| 50 | + db.db.get('@name', (err, node) => { |
| 51 | + expect(err).to.not.be.a('error') |
| 52 | + expect(node[0].value.toString()).to.eql(constants.DEFAULT_BASE) |
| 53 | + done() |
| 54 | + }) |
| 55 | + }) |
| 56 | + }) |
| 57 | + it('includes name (option.name)', (done) => { |
| 58 | + db = hypergraph(ramStore, { base: 'this://' }) |
| 59 | + db.on('ready', () => { |
| 60 | + db.db.get('@name', (err, node) => { |
| 61 | + expect(err).to.not.be.a('error') |
| 62 | + expect(node[0].value.toString()).to.eql('this://') |
| 63 | + done() |
| 64 | + }) |
| 65 | + }) |
| 66 | + }) |
| 67 | + it('includes default prefixes', (done) => { |
| 68 | + db = hypergraph(ramStore) |
| 69 | + db.on('ready', () => { |
| 70 | + const stream = db.db.createReadStream('@prefix/') |
| 71 | + stream.on('data', (nodes) => { |
| 72 | + |
| 73 | + }) |
| 74 | + stream.on('error', done) |
| 75 | + stream.on('end', () => { |
| 76 | + done() |
| 77 | + }) |
| 78 | + }) |
| 79 | + }) |
| 80 | + }) |
| 81 | + context('when loading db that already exists', () => { |
| 82 | + it('does not add new metadata') |
| 83 | + it('overrides options with metadata set in hyperdb (index)') |
| 84 | + it('overrides options with metadata set in hyperdb (name)') |
| 85 | + }) |
| 86 | +}) |
0 commit comments