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

Commit

Permalink
test: use os.tmpdir() (#1126)
Browse files Browse the repository at this point in the history
* test: use os.tmpdir()

* give time for libp2p to start

* test: use hat() for a unique name
  • Loading branch information
richardschneider authored and daviddias committed Dec 5, 2017
1 parent 9305329 commit 5d7e1f2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions test/cli/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const ipfsCmd = require('../utils/ipfs-exec')
const pull = require('pull-stream')
const toPull = require('stream-to-pull-stream')
const os = require('os')
const fs = require('fs')
const path = require('path')
const hat = require('hat')
const fs = require('fs')

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

Expand Down Expand Up @@ -65,7 +66,7 @@ describe('daemon', () => {
let ipfs

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

Expand Down
2 changes: 1 addition & 1 deletion test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('bitswap', function () {

afterEach(function (done) {
this.timeout(60 * 1000)
inProcNode.stop(() => done())
setTimeout(() => inProcNode.stop(() => done()), 500)
})

describe('transfer a block between', () => {
Expand Down
5 changes: 4 additions & 1 deletion test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const series = require('async/series')
const os = require('os')
const path = require('path')
const hat = require('hat')

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

const node = new IPFS({
repo: '/tmp/ipfs-repo-' + Math.random(),
repo: path.join(os.tmpdir(), 'ipfs-repo-' + hat()),
config: {
Addresses: {
Swarm: []
Expand Down
6 changes: 4 additions & 2 deletions test/interop/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ chai.use(dirtyChai)
const waterfall = require('async/waterfall')
const crypto = require('crypto')
const os = require('os')
const path = require('path')
const hat = require('hat')

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

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

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

const jsDaemon = new JsDaemon({init: true, disposable: false, path: dir})
Expand Down
3 changes: 2 additions & 1 deletion test/utils/interop-daemon-spawner/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
const os = require('os')
const crypto = require('libp2p-crypto')
const path = require('path')
const hat = require('hat')

exports.tmpDir = (prefix) => {
return path.join(
os.tmpdir(),
prefix || 'js-ipfs-interop',
crypto.randomBytes(32).toString('hex')
hat()
)
}
4 changes: 3 additions & 1 deletion test/utils/ipfs-factory-instance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const series = require('async/series')
const each = require('async/each')
const hat = require('hat')
const os = require('os')
const path = require('path')

const defaultConfig = require('./default-config.json')
const IPFS = require('../../../src/core')
Expand Down Expand Up @@ -30,7 +32,7 @@ function Factory () {
}

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

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

0 comments on commit 5d7e1f2

Please sign in to comment.