Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 5d7e1f2

Browse files
richardschneiderdaviddias
authored andcommitted
test: use os.tmpdir() (#1126)
* test: use os.tmpdir() * give time for libp2p to start * test: use hat() for a unique name
1 parent 9305329 commit 5d7e1f2

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

test/cli/daemon.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ const ipfsCmd = require('../utils/ipfs-exec')
77
const pull = require('pull-stream')
88
const toPull = require('stream-to-pull-stream')
99
const os = require('os')
10-
const fs = require('fs')
1110
const path = require('path')
11+
const hat = require('hat')
12+
const fs = require('fs')
1213

1314
const isWindows = os.platform() === 'win32'
1415

@@ -65,7 +66,7 @@ describe('daemon', () => {
6566
let ipfs
6667

6768
beforeEach(() => {
68-
repoPath = '/tmp/ipfs-test-not-found-' + Math.random().toString().substring(2, 8)
69+
repoPath = path.join(os.tmpdir(), 'ipfs-test-not-found-' + hat())
6970
ipfs = ipfsCmd(repoPath)
7071
})
7172

test/core/bitswap.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('bitswap', function () {
111111

112112
afterEach(function (done) {
113113
this.timeout(60 * 1000)
114-
inProcNode.stop(() => done())
114+
setTimeout(() => inProcNode.stop(() => done()), 500)
115115
})
116116

117117
describe('transfer a block between', () => {

test/core/create-node.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
99
const series = require('async/series')
10+
const os = require('os')
11+
const path = require('path')
12+
const hat = require('hat')
1013

1114
const isNode = require('detect-node')
1215
const IPFS = require('../../src/core')
@@ -19,7 +22,7 @@ describe('create node', function () {
1922
this.timeout(80 * 1000)
2023

2124
const node = new IPFS({
22-
repo: '/tmp/ipfs-repo-' + Math.random(),
25+
repo: path.join(os.tmpdir(), 'ipfs-repo-' + hat()),
2326
config: {
2427
Addresses: {
2528
Swarm: []

test/interop/repo.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ chai.use(dirtyChai)
88
const waterfall = require('async/waterfall')
99
const crypto = require('crypto')
1010
const os = require('os')
11+
const path = require('path')
12+
const hat = require('hat')
1113

1214
const GoDaemon = require('../utils/interop-daemon-spawner/go')
1315
const JsDaemon = require('../utils/interop-daemon-spawner/js')
@@ -22,7 +24,7 @@ function catAndCheck (daemon, hash, data, callback) {
2224

2325
describe('repo', () => {
2426
it('read repo: go -> js', (done) => {
25-
const dir = os.tmpdir() + '/' + Math.ceil(Math.random() * 10000)
27+
const dir = path.join(os.tmpdir(), hat())
2628
const data = crypto.randomBytes(1024 * 5)
2729

2830
const goDaemon = new GoDaemon({
@@ -57,7 +59,7 @@ describe('repo', () => {
5759
// This was last due to an update on go-ipfs that changed how datastore is
5860
// configured
5961
it.skip('read repo: js -> go', (done) => {
60-
const dir = os.tmpdir() + '/' + Math.ceil(Math.random() * 10000)
62+
const dir = path.join(os.tmpdir(), hat())
6163
const data = crypto.randomBytes(1024 * 5)
6264

6365
const jsDaemon = new JsDaemon({init: true, disposable: false, path: dir})

test/utils/interop-daemon-spawner/util.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
const os = require('os')
44
const crypto = require('libp2p-crypto')
55
const path = require('path')
6+
const hat = require('hat')
67

78
exports.tmpDir = (prefix) => {
89
return path.join(
910
os.tmpdir(),
1011
prefix || 'js-ipfs-interop',
11-
crypto.randomBytes(32).toString('hex')
12+
hat()
1213
)
1314
}

test/utils/ipfs-factory-instance/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const series = require('async/series')
44
const each = require('async/each')
55
const hat = require('hat')
6+
const os = require('os')
7+
const path = require('path')
68

79
const defaultConfig = require('./default-config.json')
810
const IPFS = require('../../../src/core')
@@ -30,7 +32,7 @@ function Factory () {
3032
}
3133

3234
if (!repoPath) {
33-
repoPath = '/tmp/.ipfs-' + hat()
35+
repoPath = path.join(os.tmpdir(), '.ipfs-' + hat())
3436
}
3537

3638
const config = Object.assign({}, defaultConfig, suppliedConfig)

0 commit comments

Comments
 (0)