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

test: use os.tmpdir() #1126

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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