test: configurable and unique test directory path
- Multiple parallel runs of the same test will not conflict as a unique identifier is added to the test directory. - The base test directory can be configured for various environments, and can be changed via the environment variable `TEMP`, see the implementation of `os.tmpdir()` for specific details.
This commit is contained in:
parent
50fe51ca32
commit
54383578fb
@ -9,7 +9,7 @@ const assert = require('./util/assert');
|
||||
const common = require('./util/common');
|
||||
const {resolve} = require('path');
|
||||
const fs = require('bfile');
|
||||
const {rimraf} = require('./util/common');
|
||||
const {rimraf, testdir} = require('./util/common');
|
||||
const random = require('bcrypto/lib/random');
|
||||
|
||||
const vectors = [
|
||||
@ -618,7 +618,7 @@ describe('BlockStore', function() {
|
||||
});
|
||||
|
||||
describe('FileBlockStore (Integration 1)', function() {
|
||||
const location = '/tmp/bcoin-blockstore-test';
|
||||
const location = testdir('blockstore');
|
||||
let store = null;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -948,7 +948,7 @@ describe('BlockStore', function() {
|
||||
});
|
||||
|
||||
describe('FileBlockStore (Integration 2)', function() {
|
||||
const location = '/tmp/bcoin-blockstore-test';
|
||||
const location = testdir('blockstore');
|
||||
let store = null;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -1101,7 +1101,7 @@ describe('BlockStore', function() {
|
||||
});
|
||||
|
||||
describe('LevelBlockStore', function() {
|
||||
const location = '/tmp/bcoin-blockstore-test';
|
||||
const location = testdir('blockstore');
|
||||
let store = null;
|
||||
|
||||
beforeEach(async () => {
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const {tmpdir} = require('os');
|
||||
const path = require('path');
|
||||
const fs = require('bfile');
|
||||
const bio = require('bufio');
|
||||
const {randomBytes} = require('bcrypto/lib/random');
|
||||
const Block = require('../../lib/primitives/block');
|
||||
const MerkleBlock = require('../../lib/primitives/merkleblock');
|
||||
const Headers = require('../../lib/primitives/headers');
|
||||
@ -85,8 +87,15 @@ common.writeTX = function writeTX(name, tx, view) {
|
||||
common.writeFile(`${name}-undo.raw`, undoRaw);
|
||||
};
|
||||
|
||||
common.testdir = function(name) {
|
||||
assert(/^[a-z]+$/.test(name), 'Invalid name');
|
||||
|
||||
const uniq = randomBytes(4).toString('hex');
|
||||
return path.join(tmpdir(), `bcoin-test-${name}-${uniq}`);
|
||||
};
|
||||
|
||||
common.rimraf = async function(p) {
|
||||
const allowed = new RegExp('^\/tmp\/(.*)$');
|
||||
const allowed = /bcoin\-test\-[a-z]+\-[a-f0-9]{8}(\/[a-z]+)?$/;
|
||||
if (!allowed.test(p))
|
||||
throw new Error(`Path not allowed: ${p}.`);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user