This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtest.js
74 lines (63 loc) · 1.72 KB
/
test.js
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
'use strict'
const IPFS = require('ipfs')
const execa = require('execa')
const os = require('os')
const path = require('path')
const nanoid = require('nanoid')
const {
waitForOutput
} = require('test-ipfs-example/utils')
async function testCli () {
await Promise.all([
startCliNode(),
startCliNode()
])
}
async function startCliNode () {
const repoDir = path.join(os.tmpdir(), `repo-${nanoid()}`)
const opts = {
env: {
...process.env,
IPFS_PATH: repoDir
}
}
const ipfs = require.resolve('ipfs/src/cli/bin.js')
await execa(ipfs, ['init'], opts)
await execa(ipfs, ['config', 'Addresses.Swarm', '--json', JSON.stringify([`/ip4/0.0.0.0/tcp/0`, `/ip4/127.0.0.1/tcp/0/ws`])], opts)
await execa(ipfs, ['config', 'Addresses.API', `/ip4/127.0.0.1/tcp/0`], opts)
await execa(ipfs, ['config', 'Addresses.Gateway', `/ip4/127.0.0.1/tcp/0`], opts)
return waitForOutput('Daemon is ready', ipfs, ['daemon'], opts)
}
async function testProgramatically () {
await Promise.all([
startProgramaticNode(),
startProgramaticNode()
])
}
async function startProgramaticNode () {
const repoDir = path.join(os.tmpdir(), `repo-${nanoid()}`)
const node = await IPFS.create({
repo: repoDir,
config: {
Addresses: {
Swarm: [
`/ip4/0.0.0.0/tcp/0`,
`/ip4/127.0.0.1/tcp/0/ws`
],
API: `/ip4/127.0.0.1/tcp/0`,
Gateway: `/ip4/127.0.0.1/tcp/0`
},
Bootstrap: []
}
})
console.info('Stopping programmatic node')
await node.stop()
}
async function runTest () {
console.info('Testing CLI recipe')
await testCli()
console.info('Testing Programmatic recipe')
await testProgramatically()
console.info('Done!')
}
module.exports = runTest