Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 2f6ba3d

Browse files
committed
Make it possible to use a running IPFS daemon for tests.
1 parent c4f2bdc commit 2f6ba3d

File tree

5 files changed

+110
-80
lines changed

5 files changed

+110
-80
lines changed

gulpfile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const gulp = require('gulp')
55
require('./test/setup/spawn-daemons')
66
require('./test/factory/factory-tasks')
77

8-
gulp.task('test:node:before', ['daemons:start', 'factory:start'])
9-
gulp.task('test:node:after', ['daemons:stop', 'factory:stop'])
10-
gulp.task('test:browser:before', ['daemons:start', 'factory:start'])
11-
gulp.task('test:browser:after', ['daemons:stop', 'factory:stop'])
8+
gulp.task('test:node:before', ['factory:start'])
9+
gulp.task('test:node:after', ['factory:stop'])
10+
gulp.task('test:browser:before', ['factory:start'])
11+
gulp.task('test:browser:after', ['factory:stop'])
1212

1313
require('aegir/gulp')(gulp)

test/factory/daemon-spawner.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Factory () {
1313

1414
const nodes = []
1515

16-
this.spawnNode = (repoPath, config, callback) => {
16+
this.spawnNode = (repoPath, config, useLocalDaemon, callback) => {
1717
if (typeof repoPath === 'function') {
1818
callback = repoPath
1919
repoPath = undefined
@@ -35,13 +35,23 @@ function Factory () {
3535
// This will come once the new ipfsd-ctl is
3636
// complete: https://github.com/ipfs/js-ipfsd-ctl/pull/89
3737

38-
spawnEphemeralNode((err, node) => {
39-
if (err) {
40-
return callback(err)
41-
}
42-
nodes.push(node)
43-
callback(null, node.apiAddr)
44-
})
38+
if (useLocalDaemon) {
39+
spawnLocalNode((err, node) => {
40+
if (err) {
41+
return callback(err)
42+
}
43+
nodes.push(node)
44+
callback(null, node.apiAddr)
45+
})
46+
} else {
47+
spawnEphemeralNode((err, node) => {
48+
if (err) {
49+
return callback(err)
50+
}
51+
nodes.push(node)
52+
callback(null, node.apiAddr)
53+
})
54+
}
4555
}
4656

4757
this.dismantle = function (callback) {
@@ -52,6 +62,22 @@ function Factory () {
5262
}
5363
}
5464

65+
function spawnLocalNode (callback) {
66+
ipfsd.local((err, node) => {
67+
if (err) {
68+
return callback(err)
69+
}
70+
71+
node.startDaemon((err, ipfs) => {
72+
if (err) {
73+
return callback(err)
74+
}
75+
76+
callback(null, node)
77+
})
78+
})
79+
}
80+
5581
function spawnEphemeralNode (callback) {
5682
ipfsd.disposable((err, node) => {
5783
if (err) {

test/factory/factory-client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Factory () {
1717
let sioConnected = false
1818
let ioC
1919

20-
this.spawnNode = (repoPath, config, callback) => {
20+
this.spawnNode = (repoPath, config, useLocalDaemon, callback) => {
2121
if (typeof repoPath === 'function') {
2222
callback = repoPath
2323
repoPath = undefined
@@ -26,6 +26,10 @@ function Factory () {
2626
callback = config
2727
config = undefined
2828
}
29+
if (typeof useLocalDaemon === 'function') {
30+
callback = useLocalDaemon
31+
useLocalDaemon = false
32+
}
2933

3034
if (sioConnected) {
3135
spawnNode()
@@ -43,7 +47,7 @@ function Factory () {
4347
const ipfs = ipfsAPI(apiAddr)
4448
callback(null, ipfs)
4549
})
46-
ioC.emit('fs-spawn-node', repoPath, config)
50+
ioC.emit('fs-spawn-node', repoPath, config, useLocalDaemon)
4751
}
4852
}
4953

test/factory/factory-server-routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module.exports = (http) => {
1414
socket.on('fs-dismantle', dismantle.bind(socket))
1515
}
1616

17-
function spawnNode (repoPath, config) {
18-
ds.spawnNode(repoPath, config, (err, apiAddr) => {
17+
function spawnNode (repoPath, config, useLocalDaemon) {
18+
ds.spawnNode(repoPath, config, useLocalDaemon, (err, apiAddr) => {
1919
if (err) {
2020
throw err
2121
}

test/setup/setup-ipfs-api-clients.js

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
/* eslint-env mocha */
2-
'use strict'
1+
// /* eslint-env mocha */
2+
// 'use strict'
33

4-
const ipfsAPI = require('./../../src/index.js')
5-
const apiAddrs = require('./tmp-disposable-nodes-addrs.json')
4+
// // const ipfsAPI = require('./../../src/index.js')
5+
// // const apiAddrs = require('./tmp-disposable-nodes-addrs.json')
66

7-
// a, b, c
8-
global.apiClients = {}
7+
// // a, b, c
8+
// global.apiClients = {}
99

10-
const addrs = {}
10+
// const addrs = {}
1111

12-
function connectNodes (done) {
13-
let counter = 0
12+
// // function connectNodes (done) {
13+
// // let counter = 0
1414

15-
function collectAddr (key, cb) {
16-
global.apiClients[key].id((err, id) => {
17-
if (err) {
18-
throw err
19-
}
20-
// note to self: HTTP API port !== Node port
21-
addrs[key] = id.addresses[0]
22-
cb()
23-
})
24-
}
15+
// // function collectAddr (key, cb) {
16+
// // global.apiClients[key].id((err, id) => {
17+
// // if (err) {
18+
// // throw err
19+
// // }
20+
// // // note to self: HTTP API port !== Node port
21+
// // addrs[key] = id.addresses[0]
22+
// // cb()
23+
// // })
24+
// // }
2525

26-
function dial () {
27-
global.apiClients.a.swarm.connect(addrs.b, (err, res) => {
28-
if (err) {
29-
throw err
30-
}
31-
global.apiClients.a.swarm.connect(addrs.c, (err) => {
32-
if (err) {
33-
throw err
34-
}
35-
done()
36-
})
37-
})
38-
}
26+
// // function dial () {
27+
// // global.apiClients.a.swarm.connect(addrs.b, (err, res) => {
28+
// // if (err) {
29+
// // throw err
30+
// // }
31+
// // global.apiClients.a.swarm.connect(addrs.c, (err) => {
32+
// // if (err) {
33+
// // throw err
34+
// // }
35+
// // done()
36+
// // })
37+
// // })
38+
// // }
3939

40-
function finish () {
41-
counter++
42-
if (counter === 2) {
43-
dial()
44-
}
45-
}
40+
// // function finish () {
41+
// // counter++
42+
// // if (counter === 2) {
43+
// // dial()
44+
// // }
45+
// // }
4646

47-
collectAddr('b', finish)
48-
collectAddr('c', finish)
49-
}
47+
// // collectAddr('b', finish)
48+
// // collectAddr('c', finish)
49+
// // }
5050

51-
function disconnectNodes (done) {
52-
global.apiClients.a.swarm.disconnect(addrs.b, (err) => {
53-
if (err) {
54-
throw err
55-
}
56-
global.apiClients.a.swarm.disconnect(addrs.c, (err) => {
57-
if (err) {
58-
throw err
59-
}
60-
done()
61-
})
62-
})
63-
}
51+
// // function disconnectNodes (done) {
52+
// // global.apiClients.a.swarm.disconnect(addrs.b, (err) => {
53+
// // if (err) {
54+
// // throw err
55+
// // }
56+
// // global.apiClients.a.swarm.disconnect(addrs.c, (err) => {
57+
// // if (err) {
58+
// // throw err
59+
// // }
60+
// // done()
61+
// // })
62+
// // })
63+
// // }
6464

65-
before(function (done) {
66-
this.timeout(20000)
65+
// // before(function (done) {
66+
// // this.timeout(20000)
6767

68-
Object.keys(apiAddrs).forEach((key) => {
69-
global.apiClients[key] = ipfsAPI(apiAddrs[key])
70-
})
68+
// // Object.keys(apiAddrs).forEach((key) => {
69+
// // global.apiClients[key] = ipfsAPI(apiAddrs[key])
70+
// // })
7171

72-
connectNodes(done)
73-
})
72+
// // connectNodes(done)
73+
// // })
7474

75-
after(function (done) {
76-
disconnectNodes(done)
77-
})
75+
// // after(function (done) {
76+
// // disconnectNodes(done)
77+
// // })

0 commit comments

Comments
 (0)