Skip to content

Commit

Permalink
Merge pull request bcoin-org#884 from tuxcanfly/blockstore-paths
Browse files Browse the repository at this point in the history
test: fix blockstore paths for windows
  • Loading branch information
braydonf committed Oct 17, 2019
2 parents 7b47913 + e411946 commit e678642
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 22 additions & 14 deletions test/blockstore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,20 @@ describe('BlockStore', function() {
});

describe('FileBlockStore (Unit)', function() {
const location = '/tmp/.bcoin/blocks';
const location = () => {
switch (process.platform) {
case 'win32':
return '\\tmp\\.bcoin\\blocks\\';
default:
return '/tmp/.bcoin/blocks/';
}
};

let store = null;

before(() => {
store = new FileBlockStore({
location: location,
location: location(),
maxFileLength: 1024
});
});
Expand All @@ -301,7 +309,7 @@ describe('BlockStore', function() {
};

const store = new FileBlockStore({
location: '/tmp/.bcoin/blocks',
location: location(),
maxFileLength: 1024,
logger: logger
});
Expand Down Expand Up @@ -330,7 +338,7 @@ describe('BlockStore', function() {

try {
new FileBlockStore({
location: location,
location: location(),
maxFileLength: 'notanumber'
});
} catch (e) {
Expand Down Expand Up @@ -358,32 +366,32 @@ describe('BlockStore', function() {
describe('filepath', function() {
it('will give correct path (0)', () => {
const filepath = store.filepath(types.BLOCK, 0);
assert.equal(filepath, '/tmp/.bcoin/blocks/blk00000.dat');
assert.equal(filepath, `${location()}blk00000.dat`);
});

it('will give correct path (1)', () => {
const filepath = store.filepath(types.BLOCK, 7);
assert.equal(filepath, '/tmp/.bcoin/blocks/blk00007.dat');
assert.equal(filepath, `${location()}blk00007.dat`);
});

it('will give correct path (2)', () => {
const filepath = store.filepath(types.BLOCK, 23);
assert.equal(filepath, '/tmp/.bcoin/blocks/blk00023.dat');
assert.equal(filepath, `${location()}blk00023.dat`);
});

it('will give correct path (3)', () => {
const filepath = store.filepath(types.BLOCK, 456);
assert.equal(filepath, '/tmp/.bcoin/blocks/blk00456.dat');
assert.equal(filepath, `${location()}blk00456.dat`);
});

it('will give correct path (4)', () => {
const filepath = store.filepath(types.BLOCK, 8999);
assert.equal(filepath, '/tmp/.bcoin/blocks/blk08999.dat');
assert.equal(filepath, `${location()}blk08999.dat`);
});

it('will give correct path (5)', () => {
const filepath = store.filepath(types.BLOCK, 99999);
assert.equal(filepath, '/tmp/.bcoin/blocks/blk99999.dat');
assert.equal(filepath, `${location()}blk99999.dat`);
});

it('will fail over max size', () => {
Expand All @@ -400,7 +408,7 @@ describe('BlockStore', function() {

it('will give undo type', () => {
const filepath = store.filepath(types.UNDO, 99999);
assert.equal(filepath, '/tmp/.bcoin/blocks/blu99999.dat');
assert.equal(filepath, `${location()}blu99999.dat`);
});

it('will fail for unknown prefix', () => {
Expand Down Expand Up @@ -446,7 +454,7 @@ describe('BlockStore', function() {
filerecord: {
used: 0
},
filepath: '/tmp/.bcoin/blocks/blk00020.dat'
filepath: `${location()}blk00020.dat`
};
};
store.db.has = () => false;
Expand Down Expand Up @@ -476,7 +484,7 @@ describe('BlockStore', function() {
filerecord: {
used: 0
},
filepath: '/tmp/.bcoin/blocks/blk00020.dat'
filepath: `${location()}blk00020.dat`
};
};
store.db.has = () => false;
Expand Down Expand Up @@ -515,7 +523,7 @@ describe('BlockStore', function() {
filerecord: {
used: 0
},
filepath: '/tmp/.bcoin/blocks/blk00020.dat'
filepath: `${location()}blk00020.dat`
};
};
store.db.has = () => false;
Expand Down
2 changes: 1 addition & 1 deletion test/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ common.testdir = function(name) {
};

common.rimraf = async function(p) {
const allowed = /bcoin\-test\-[a-z]+\-[a-f0-9]{8}(\/[a-z]+)?$/;
const allowed = /bcoin\-test\-[a-z]+\-[a-f0-9]{8}((\\|\/)[a-z]+)?$/;
if (!allowed.test(p))
throw new Error(`Path not allowed: ${p}.`);

Expand Down

0 comments on commit e678642

Please sign in to comment.