it('throws on opening an index file with invalid metadata', function() { const indexFile = dataDirectory + '/.index'; const metadataBuffer = Buffer.allocUnsafe(8 + 4 + 3); metadataBuffer.write("nesidx01", 0, 8, 'utf8'); metadataBuffer.writeUInt32BE(255, 8); metadataBuffer.write("{x$", 12, 3, 'utf8'); fs.writeFileSync(indexFile, metadataBuffer); expect(() => index = new Index(indexFile)).to.throwError(/Invalid metadata/); });
it('validates document size', function() { partition.open(); fillPartition(10); partition.close(); partition.open(); expect(partition.readFrom(0, 6)).to.be('foobar'); expect(() => partition.readFrom(0, 4)).to.throwError((e) => { expect(e).to.be.a(Partition.InvalidDataSizeError); }); });
it('throws when reopening with different matcher', function() { storage = createStorage(); storage.open(); storage.ensureIndex('foo-matcher', () => true); storage.close(); storage = createStorage(); storage.open(); expect(() => storage.ensureIndex('foo-matcher', (doc) => doc.type === 'Foo')).to.throwError(); });
it('throws when opened in read-only mode', function() { eventstore = new EventStore({ storageDirectory }); eventstore.close(); eventstore = new EventStore({ storageDirectory, readOnly: true }); expect(() => eventstore.commit('foo-bar', { foo: 'bar' })).to.throwError(); });
it('throws when an unfinished write is found', function() { partition.open(); const position = partition.write('foobar'); partition.close(); let fd = fs.openSync('test/data/.part', 'r+'); fs.ftruncateSync(fd, partition.headerSize + position + partition.documentWriteSize('foobar'.length) - 4); fs.closeSync(fd); partition.open(); expect(() => partition.readFrom(0)).to.throwError((e) => { expect(e).to.be.a(Partition.CorruptFileError); }); });
it('detect unmatched custom command', function () { var tpl = '{{#x.y()}}\n{{/x}}'; expect(function () { try { new XTemplate(tpl).render(); } catch (e) { throw e; } }).to.throwError('Syntax error at line 2, col 4:\n' + 'expect {{/x,y}} not {{/x}}'); });
it('throws on opening an non-index file', function() { const indexFile = dataDirectory + '/.index'; fs.writeFileSync(indexFile, 'foo'); expect(() => index = new Index(indexFile)).to.throwError(/Invalid file header/); });
it('bone.save() should allow unset attributes be overridden', async function() { await Post.create({ title: 'New Post'}); const post = await Post.select('id').first; expect(() => post.title).to.throwError(); post.title = 'Skeleton King'; await post.save(); expect(await Post.first).to.eql(post); });
it('throws on invalid range', function() { storage = createStorage(); storage.open(); for (let i = 1; i <= 10; i++) { storage.write({ foo: i }); } storage.close(); storage.open(); expect(() => storage.readRange(0).next()).to.throwError(); expect(() => storage.readRange(11).next()).to.throwError(); expect(() => storage.readRange(1, 14).next()).to.throwError(); });
it('throws when reading from an invalid position', function() { partition.open(); fillPartition(10); partition.close(); partition.open(); expect(() => console.log(partition.readFrom(3))).to.throwError(); });
it('.find { select }', async function() { const post = await Post.findOne({ title: 'New Post' }, { select: 'title' }); expect(post.title).to.equal('New Post'); expect(() => post.content).to.throwError(); });
it('bone.save() should throw if missing primary key', async function() { await Post.create({ title: 'New Post' }); const post = await Post.findOne().select('title'); expect(() => post.id).to.throwError(); post.title = 'Skeleton King'; await assert.rejects(async () => { await post.save(); }, /primary key/); });
it('throws when no events specified', function() { eventstore = new EventStore({ storageDirectory }); expect(() => eventstore.commit('foo-bar')).to.throwError(); });
it("Should throw on unknown transformer", function() { expect(function() { return SQL`SELECT * FROM $optimus${{id : 44}}`; }).to.throwError(/Unknown transformer optimus/); });
it('throws on opening an index file with too large metadata size', function() { const indexFile = dataDirectory + '/.index'; const metadataBuffer = Buffer.allocUnsafe(8 + 4 + 3); metadataBuffer.write("nesidx01", 0, 8, 'utf8'); metadataBuffer.writeUInt32BE(255, 8); metadataBuffer.write("{}\n", 12, 3, 'utf8'); fs.writeFileSync(indexFile, metadataBuffer); expect(() => index = new Index(indexFile)).to.throwError(/Invalid index file/); });