forked from ipfs/js-ipfs-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.js
More file actions
106 lines (95 loc) · 2.33 KB
/
node.js
File metadata and controls
106 lines (95 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* eslint-env mocha */
'use strict'
const ncp = require('ncp').ncp
const rimraf = require('rimraf')
const fs = require('fs')
const path = require('path')
const series = require('async/series')
const chai = require('chai')
chai.use(require('dirty-chai'))
const IPFSRepo = require('../src')
describe('IPFS Repo Tests onNode.js', () => {
require('./options-test')
const customLock = {
lockName: 'test.lock',
lock: (dir, callback) => {
customLock.locked(dir, (err, isLocked) => {
if (err || isLocked) {
return callback(new Error('already locked'))
}
const lockPath = path.join(dir, customLock.lockName)
fs.writeFileSync(lockPath, '')
callback(null, {
close: (cb) => {
rimraf(lockPath, cb)
}
})
})
},
locked: (dir, callback) => {
fs.stat(path.join(dir, customLock.lockName), (err, stats) => {
if (err) {
callback(null, false)
} else {
callback(null, true)
}
})
}
}
const repos = [{
name: 'default inited',
opts: undefined,
init: true
}, {
name: 'memory',
opts: {
fs: require('interface-datastore').MemoryDatastore,
level: require('memdown'),
lock: 'memory'
},
init: true
}, {
name: 'custom locker',
opts: {
lock: customLock
},
init: true
}, {
name: 'default existing',
opts: undefined,
init: false
}]
repos.forEach((r) => describe(r.name, () => {
const testRepoPath = path.join(__dirname, 'test-repo')
const date = Date.now().toString()
const repoPath = testRepoPath + '-for-' + date
const repo = new IPFSRepo(repoPath, r.opts)
before((done) => {
series([
(cb) => {
if (r.init) {
repo.init({}, cb)
} else {
ncp(testRepoPath, repoPath, cb)
}
},
(cb) => repo.open(cb)
], done)
})
after((done) => {
series([
(cb) => repo.close(cb),
(cb) => rimraf(repoPath, cb)
], done)
})
require('./repo-test')(repo)
require('./blockstore-test')(repo)
require('./datastore-test')(repo)
require('./keystore-test')(repo)
require('./stat-test')(repo)
require('./lock-test')(repo)
if (!r.init) {
require('./interop-test')(repo)
}
}))
})