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

Commit 366f9b9

Browse files
committed
adds init tests for default assets
1 parent 572cd2d commit 366f9b9

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

tests/test-core/test-init-node.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* eslint-env mocha */
2+
3+
const expect = require('chai').expect
4+
const IPFS = require('../../src/core')
5+
const IPFSRepo = require('ipfs-repo')
6+
7+
function createTestRepo () {
8+
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/'
9+
// console.log('repo', repoPath)
10+
11+
var store
12+
var teardown
13+
14+
const isNode = !global.window
15+
if (isNode) {
16+
store = require('fs-blob-store')
17+
teardown = (done) => {
18+
const rimraf = require('rimraf')
19+
rimraf(repoPath, (err) => {
20+
expect(err).to.not.exist
21+
done()
22+
})
23+
}
24+
} else {
25+
const idb = window.indexedDB ||
26+
window.mozIndexedDB ||
27+
window.webkitIndexedDB ||
28+
window.msIndexedDB
29+
store = require('idb-plus-blob-store')
30+
teardown = (done) => {
31+
idb.deleteDatabase(repoPath)
32+
idb.deleteDatabase(repoPath + '/blocks')
33+
done()
34+
}
35+
}
36+
37+
const options = {
38+
bits: 64,
39+
stores: {
40+
keys: store,
41+
config: store,
42+
datastore: store,
43+
logs: store,
44+
locks: store,
45+
version: store
46+
}
47+
}
48+
49+
var repo = new IPFSRepo(repoPath, options)
50+
51+
repo.teardown = teardown
52+
53+
return repo
54+
}
55+
56+
describe('node: init', function () {
57+
this.timeout(10000)
58+
59+
it('basic', (done) => {
60+
var repo = createTestRepo()
61+
const ipfs = new IPFS(repo)
62+
ipfs.init({ bits: 64 }, (err) => {
63+
expect(err).to.not.exist
64+
65+
// Check for default assets
66+
var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex')
67+
ipfs.object.get(multihash, {}, (err, node) => {
68+
expect(err).to.not.exist
69+
expect(node.links).to.exist
70+
71+
repo.teardown(done)
72+
})
73+
})
74+
})
75+
76+
// test --empty-repo
77+
})

tests/test-core/test-init.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('init', function () {
5959
it('basic', (done) => {
6060
var repo = createTestRepo()
6161
const ipfs = new IPFS(repo)
62-
ipfs.init({}, (err) => {
62+
ipfs.init({ emptyRepo: true }, (err) => {
6363
expect(err).to.not.exist
6464

6565
repo.exists((err, res) => {
@@ -81,10 +81,10 @@ describe('init', function () {
8181
var repo2 = createTestRepo()
8282
const ipfsShort = new IPFS(repo1)
8383
const ipfsLong = new IPFS(repo2)
84-
ipfsShort.init({ bits: 128 }, (err) => {
84+
ipfsShort.init({ bits: 128, emptyRepo: true }, (err) => {
8585
expect(err).to.not.exist
8686

87-
ipfsLong.init({ bits: 256 }, (err) => {
87+
ipfsLong.init({ bits: 256, emptyRepo: true }, (err) => {
8888
expect(err).to.not.exist
8989

9090
repo1.config.get((err, config1) => {
@@ -107,7 +107,7 @@ describe('init', function () {
107107
var repo = createTestRepo()
108108
const ipfs1 = new IPFS(repo)
109109
const ipfs2 = new IPFS(repo)
110-
ipfs1.init({ bits: 128 }, (err) => {
110+
ipfs1.init({ bits: 128, emptyRepo: true }, (err) => {
111111
expect(err).to.not.exist
112112

113113
ipfs2.init({ bits: 128, force: false }, (err) => {
@@ -121,6 +121,4 @@ describe('init', function () {
121121
})
122122
})
123123
})
124-
125-
// test --empty-repo
126124
})

0 commit comments

Comments
 (0)