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

Commit

Permalink
Merge pull request #98 from noffle/tests-setup-teardown
Browse files Browse the repository at this point in the history
moves temp-repo creation into its own module
  • Loading branch information
daviddias committed Mar 27, 2016
2 parents 6421678 + 5423f04 commit cd6797d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 104 deletions.
54 changes: 54 additions & 0 deletions tests/temp-repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-env mocha */

const expect = require('chai').expect
const IPFSRepo = require('ipfs-repo')

function createTempRepo () {
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/'

var store
var teardown

const isNode = !global.window
if (isNode) {
store = require('fs-blob-store')
teardown = (done) => {
const rimraf = require('rimraf')
rimraf(repoPath, (err) => {
expect(err).to.not.exist
done()
})
}
} else {
const idb = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB
store = require('idb-plus-blob-store')
teardown = (done) => {
idb.deleteDatabase(repoPath)
idb.deleteDatabase(repoPath + '/blocks')
done()
}
}

const options = {
bits: 64,
stores: {
keys: store,
config: store,
datastore: store,
logs: store,
locks: store,
version: store
}
}

var repo = new IPFSRepo(repoPath, options)

repo.teardown = teardown

return repo
}

module.exports = createTempRepo
54 changes: 3 additions & 51 deletions tests/test-core/test-init-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,13 @@

const expect = require('chai').expect
const IPFS = require('../../src/core')
const IPFSRepo = require('ipfs-repo')

function createTestRepo () {
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/'

var store
var teardown

const isNode = !global.window
if (isNode) {
store = require('fs-blob-store')
teardown = (done) => {
const rimraf = require('rimraf')
rimraf(repoPath, (err) => {
expect(err).to.not.exist
done()
})
}
} else {
const idb = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB
store = require('idb-plus-blob-store')
teardown = (done) => {
idb.deleteDatabase(repoPath)
idb.deleteDatabase(repoPath + '/blocks')
done()
}
}

const options = {
bits: 64,
stores: {
keys: store,
config: store,
datastore: store,
logs: store,
locks: store,
version: store
}
}

var repo = new IPFSRepo(repoPath, options)

repo.teardown = teardown

return repo
}
const createTempRepo = require('../temp-repo')

describe('node: init', function () {
this.timeout(10000)

it('init docs written', (done) => {
var repo = createTestRepo()
var repo = createTempRepo()
const ipfs = new IPFS(repo)
ipfs.init({ bits: 64 }, (err) => {
expect(err).to.not.exist
Expand All @@ -73,7 +25,7 @@ describe('node: init', function () {
})

it('empty repo', (done) => {
var repo = createTestRepo()
var repo = createTempRepo()
const ipfs = new IPFS(repo)
ipfs.init({ bits: 64, emptyRepo: true }, (err) => {
expect(err).to.not.exist
Expand Down
58 changes: 5 additions & 53 deletions tests/test-core/test-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,13 @@

const expect = require('chai').expect
const IPFS = require('../../src/core')
const IPFSRepo = require('ipfs-repo')

function createTestRepo () {
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/'

var store
var teardown

const isNode = !global.window
if (isNode) {
store = require('fs-blob-store')
teardown = (done) => {
const rimraf = require('rimraf')
rimraf(repoPath, (err) => {
expect(err).to.not.exist
done()
})
}
} else {
const idb = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB
store = require('idb-plus-blob-store')
teardown = (done) => {
idb.deleteDatabase(repoPath)
idb.deleteDatabase(repoPath + '/blocks')
done()
}
}

const options = {
bits: 64,
stores: {
keys: store,
config: store,
datastore: store,
logs: store,
locks: store,
version: store
}
}

var repo = new IPFSRepo(repoPath, options)

repo.teardown = teardown

return repo
}
const createTempRepo = require('../temp-repo')

describe('init', function () {
this.timeout(10000)

it('basic', (done) => {
var repo = createTestRepo()
var repo = createTempRepo()
const ipfs = new IPFS(repo)
ipfs.init({ emptyRepo: true }, (err) => {
expect(err).to.not.exist
Expand All @@ -76,8 +28,8 @@ describe('init', function () {
})

it('set # of bits in key', (done) => {
var repo1 = createTestRepo()
var repo2 = createTestRepo()
var repo1 = createTempRepo()
var repo2 = createTempRepo()
const ipfsShort = new IPFS(repo1)
const ipfsLong = new IPFS(repo2)
ipfsShort.init({ bits: 128, emptyRepo: true }, (err) => {
Expand All @@ -103,7 +55,7 @@ describe('init', function () {
})

it('force init (overwrite)', (done) => {
var repo = createTestRepo()
var repo = createTempRepo()
const ipfs1 = new IPFS(repo)
const ipfs2 = new IPFS(repo)
ipfs1.init({ bits: 128, emptyRepo: true }, (err) => {
Expand Down

0 comments on commit cd6797d

Please sign in to comment.