Skip to content

Commit

Permalink
Merge pull request #170 from albe/index-test-coverage
Browse files Browse the repository at this point in the history
Increase index test coverage
  • Loading branch information
albe committed Jun 3, 2021
2 parents 9461fbe + a042dc1 commit dfb579a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/WatchesFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ const WatchesFile = Base => class extends Base {
* @returns {boolean}
*/
open() {
if (this.fd) {
return false;
if (super.open()) {
this.watchFile();
return true;
}

this.watchFile();
return super.open();
return false;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/Index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ describe('Index', function() {
expect(index.isOpen()).to.be(true);
});

it('can be opened multiple times', function() {
index = createIndex();
index.open();
expect(index.open()).to.be(false);
});

it('defaults name to ".index"', function() {
index = new Index({ dataDirectory });
expect(index.name).to.be('.index');
Expand Down Expand Up @@ -338,6 +344,11 @@ describe('Index', function() {

describe('find', function() {

it('returns 0 on an empty index', function() {
index = createIndex();
expect(index.find(1)).to.be(0);
});

it('returns 0 if no entry is lower or equal searched number', function() {
index = setupIndexWithEntries(5, i => 5 + i);
expect(index.find(index.length)).to.be(0);
Expand Down

0 comments on commit dfb579a

Please sign in to comment.