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

Commit 11a166e

Browse files
committed
refactor(tests): make each feature test isolated (launchable by itself
1 parent e5cb43c commit 11a166e

16 files changed

+409
-162
lines changed

test/interface-ipfs-core/block.spec.js

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
11
/* eslint-env mocha */
22
/* eslint max-nested-callbacks: ["error", 8] */
3-
/* globals apiClients */
43
'use strict'
54

5+
const FactoryClient = require('../factory/factory-client')
66
const expect = require('chai').expect
77

88
describe('.block', () => {
9+
let ipfs
10+
let fc
11+
12+
before(function (done) {
13+
this.timeout(20 * 1000) // slow CI
14+
fc = new FactoryClient()
15+
fc.spawnNode((err, node) => {
16+
expect(err).to.not.exist
17+
ipfs = node
18+
done()
19+
})
20+
})
21+
22+
after((done) => {
23+
fc.dismantle(done)
24+
})
25+
926
const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
1027
const blorb = Buffer('blorb')
1128

1229
it('returns an error when putting an array of files', () => {
13-
return apiClients.a.block.put([blorb, blorb], (err) => {
30+
return ipfs.block.put([blorb, blorb], (err) => {
1431
expect(err).to.be.an.instanceof(Error)
1532
})
1633
})
1734

1835
it('block.put', (done) => {
19-
apiClients.a.block.put(blorb, (err, res) => {
36+
ipfs.block.put(blorb, (err, res) => {
2037
expect(err).to.not.exist
2138
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
2239
done()
2340
})
2441
})
2542

2643
it('block.get', (done) => {
27-
apiClients.a.block.get(blorbKey, (err, res) => {
44+
ipfs.block.get(blorbKey, (err, res) => {
2845
expect(err).to.not.exist
2946

3047
let buf = ''
@@ -38,7 +55,7 @@ describe('.block', () => {
3855
})
3956

4057
it('block.stat', (done) => {
41-
apiClients.a.block.stat(blorbKey, (err, res) => {
58+
ipfs.block.stat(blorbKey, (err, res) => {
4259
expect(err).to.not.exist
4360
expect(res).to.have.property('Key')
4461
expect(res).to.have.property('Size')
@@ -48,21 +65,21 @@ describe('.block', () => {
4865

4966
describe('promise', () => {
5067
it('returns an error when putting an array of files', () => {
51-
return apiClients.a.block.put([blorb, blorb])
68+
return ipfs.block.put([blorb, blorb])
5269
.catch((err) => {
5370
expect(err).to.be.an.instanceof(Error)
5471
})
5572
})
5673

5774
it('block.put', () => {
58-
return apiClients.a.block.put(blorb)
75+
return ipfs.block.put(blorb)
5976
.then((res) => {
6077
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
6178
})
6279
})
6380

6481
it('block.get', (done) => {
65-
apiClients.a.block.get(blorbKey)
82+
ipfs.block.get(blorbKey)
6683
.then((res) => {
6784
let buf = ''
6885
res
@@ -76,7 +93,7 @@ describe('.block', () => {
7693
})
7794

7895
it('block.stat', () => {
79-
return apiClients.a.block.stat(blorbKey)
96+
return ipfs.block.stat(blorbKey)
8097
.then((res) => {
8198
expect(res).to.have.property('Key')
8299
expect(res).to.have.property('Size')

test/interface-ipfs-core/bootstrap.spec.js

+36-19
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
11
/* eslint-env mocha */
22
/* eslint max-nested-callbacks: ["error", 8] */
3-
/* globals apiClients */
43
'use strict'
54

65
const expect = require('chai').expect
6+
const FactoryClient = require('../factory/factory-client')
77

88
const invalidArg = 'this/Is/So/Invalid/'
99
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
1010

1111
describe('.bootstrap', () => {
12+
let ipfs
13+
let fc
14+
15+
before(function (done) {
16+
this.timeout(20 * 1000) // slow CI
17+
fc = new FactoryClient()
18+
fc.spawnNode((err, node) => {
19+
expect(err).to.not.exist
20+
ipfs = node
21+
done()
22+
})
23+
})
24+
25+
after((done) => {
26+
fc.dismantle(done)
27+
})
28+
1229
let peers
1330

1431
describe('.add', () => {
1532
it('returns an error when called without args or options', (done) => {
16-
return apiClients.a.bootstrap.add(null, (err) => {
33+
return ipfs.bootstrap.add(null, (err) => {
1734
expect(err).to.be.an.instanceof(Error)
1835
done()
1936
})
2037
})
2138

2239
it('returns an error when called with an invalid arg', (done) => {
23-
return apiClients.a.bootstrap.add(invalidArg, (err) => {
40+
return ipfs.bootstrap.add(invalidArg, (err) => {
2441
expect(err).to.be.an.instanceof(Error)
2542
done()
2643
})
2744
})
2845

2946
it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
30-
return apiClients.a.bootstrap.add(validIp4, (err, res) => {
47+
return ipfs.bootstrap.add(validIp4, (err, res) => {
3148
expect(err).to.not.exist
3249
expect(res).to.be.eql({ Peers: [validIp4] })
3350
peers = res.Peers
@@ -38,7 +55,7 @@ describe('.bootstrap', () => {
3855
})
3956

4057
it('returns a list of bootstrap peers when called with the default option', (done) => {
41-
return apiClients.a.bootstrap.add(null, { default: true }, (err, res) => {
58+
return ipfs.bootstrap.add(null, { default: true }, (err, res) => {
4259
expect(err).to.not.exist
4360
peers = res.Peers
4461
expect(peers).to.exist
@@ -50,7 +67,7 @@ describe('.bootstrap', () => {
5067

5168
describe('.list', () => {
5269
it('returns a list of peers', (done) => {
53-
return apiClients.a.bootstrap.list((err, res) => {
70+
return ipfs.bootstrap.list((err, res) => {
5471
expect(err).to.not.exist
5572
peers = res.Peers
5673
expect(peers).to.exist
@@ -61,14 +78,14 @@ describe('.bootstrap', () => {
6178

6279
describe('.rm', () => {
6380
it('returns an error when called with an invalid arg', (done) => {
64-
return apiClients.a.bootstrap.rm(invalidArg, (err) => {
81+
return ipfs.bootstrap.rm(invalidArg, (err) => {
6582
expect(err).to.be.an.instanceof(Error)
6683
done()
6784
})
6885
})
6986

7087
it('returns empty list because no peers removed when called without an arg or options', (done) => {
71-
return apiClients.a.bootstrap.rm(null, (err, res) => {
88+
return ipfs.bootstrap.rm(null, (err, res) => {
7289
expect(err).to.not.exist
7390
peers = res.Peers
7491
expect(peers).to.exist
@@ -78,7 +95,7 @@ describe('.bootstrap', () => {
7895
})
7996

8097
it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
81-
return apiClients.a.bootstrap.rm(null, (err, res) => {
98+
return ipfs.bootstrap.rm(null, (err, res) => {
8299
expect(err).to.not.exist
83100
peers = res.Peers
84101
expect(peers).to.exist
@@ -88,7 +105,7 @@ describe('.bootstrap', () => {
88105
})
89106

90107
it('returns list of all peers removed when all option is passed', (done) => {
91-
return apiClients.a.bootstrap.rm(null, { all: true }, (err, res) => {
108+
return ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
92109
expect(err).to.not.exist
93110
peers = res.Peers
94111
expect(peers).to.exist
@@ -100,21 +117,21 @@ describe('.bootstrap', () => {
100117
describe('.promise', () => {
101118
describe('.add', () => {
102119
it('returns an error when called without args or options', () => {
103-
return apiClients.a.bootstrap.add(null)
120+
return ipfs.bootstrap.add(null)
104121
.catch((err) => {
105122
expect(err).to.be.an.instanceof(Error)
106123
})
107124
})
108125

109126
it('returns an error when called with an invalid arg', () => {
110-
return apiClients.a.bootstrap.add(invalidArg)
127+
return ipfs.bootstrap.add(invalidArg)
111128
.catch((err) => {
112129
expect(err).to.be.an.instanceof(Error)
113130
})
114131
})
115132

116133
it('returns a list of peers when called with a valid arg (ip4)', () => {
117-
return apiClients.a.bootstrap.add(validIp4)
134+
return ipfs.bootstrap.add(validIp4)
118135
.then((res) => {
119136
expect(res).to.be.eql({ Peers: [validIp4] })
120137
peers = res.Peers
@@ -124,7 +141,7 @@ describe('.bootstrap', () => {
124141
})
125142

126143
it('returns a list of default peers when called with the default option', () => {
127-
return apiClients.a.bootstrap.add(null, { default: true })
144+
return ipfs.bootstrap.add(null, { default: true })
128145
.then((res) => {
129146
peers = res.Peers
130147
expect(peers).to.exist
@@ -135,7 +152,7 @@ describe('.bootstrap', () => {
135152

136153
describe('.list', () => {
137154
it('returns a list of peers', () => {
138-
return apiClients.a.bootstrap.list()
155+
return ipfs.bootstrap.list()
139156
.then((res) => {
140157
peers = res.Peers
141158
expect(peers).to.exist
@@ -145,14 +162,14 @@ describe('.bootstrap', () => {
145162

146163
describe('.rm', () => {
147164
it('returns an error when called with an invalid arg', () => {
148-
return apiClients.a.bootstrap.rm(invalidArg)
165+
return ipfs.bootstrap.rm(invalidArg)
149166
.catch((err) => {
150167
expect(err).to.be.an.instanceof(Error)
151168
})
152169
})
153170

154171
it('returns empty list when called without an arg or options', () => {
155-
return apiClients.a.bootstrap.rm(null)
172+
return ipfs.bootstrap.rm(null)
156173
.then((res) => {
157174
peers = res.Peers
158175
expect(peers).to.exist
@@ -161,7 +178,7 @@ describe('.bootstrap', () => {
161178
})
162179

163180
it('returns list containing the peer removed when called with a valid arg (ip4)', () => {
164-
return apiClients.a.bootstrap.rm(null)
181+
return ipfs.bootstrap.rm(null)
165182
.then((res) => {
166183
peers = res.Peers
167184
expect(peers).to.exist
@@ -170,7 +187,7 @@ describe('.bootstrap', () => {
170187
})
171188

172189
it('returns list of all peers removed when all option is passed', () => {
173-
return apiClients.a.bootstrap.rm(null, { all: true })
190+
return ipfs.bootstrap.rm(null, { all: true })
174191
.then((res) => {
175192
peers = res.Peers
176193
expect(peers).to.exist

test/interface-ipfs-core/commands.spec.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
/* eslint-env mocha */
2-
/* globals apiClients */
32
'use strict'
43

54
const expect = require('chai').expect
5+
const FactoryClient = require('../factory/factory-client')
66

77
describe('.commands', () => {
8+
let ipfs
9+
let fc
10+
11+
before(function (done) {
12+
this.timeout(20 * 1000) // slow CI
13+
fc = new FactoryClient()
14+
fc.spawnNode((err, node) => {
15+
expect(err).to.not.exist
16+
ipfs = node
17+
done()
18+
})
19+
})
20+
21+
after((done) => {
22+
fc.dismantle(done)
23+
})
24+
825
it('lists commands', (done) => {
9-
apiClients.a.commands((err, res) => {
26+
ipfs.commands((err, res) => {
1027
expect(err).to.not.exist
1128
expect(res).to.exist
1229
done()
@@ -15,7 +32,7 @@ describe('.commands', () => {
1532

1633
describe('promise', () => {
1734
it('lists commands', () => {
18-
return apiClients.a.commands()
35+
return ipfs.commands()
1936
.then((res) => {
2037
expect(res).to.exist
2138
})

test/interface-ipfs-core/diag.spec.js

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
/* eslint-env mocha */
2-
/* globals apiClients */
32
'use strict'
43

4+
const FactoryClient = require('../factory/factory-client')
55
const expect = require('chai').expect
66

77
describe('.diag', () => {
8+
let ipfs
9+
let fc
10+
11+
before(function (done) {
12+
this.timeout(20 * 1000) // slow CI
13+
fc = new FactoryClient()
14+
fc.spawnNode((err, node) => {
15+
expect(err).to.not.exist
16+
ipfs = node
17+
done()
18+
})
19+
})
20+
21+
after((done) => {
22+
fc.dismantle(done)
23+
})
24+
825
it('.diag.net', (done) => {
9-
apiClients.a.diag.net((err, res) => {
26+
ipfs.diag.net((err, res) => {
1027
expect(err).to.not.exist
1128
expect(res).to.exist
1229
done()
1330
})
1431
})
1532

1633
it('.diag.sys', (done) => {
17-
apiClients.a.diag.sys((err, res) => {
34+
ipfs.diag.sys((err, res) => {
1835
expect(err).to.not.exist
1936
expect(res).to.exist
2037
expect(res).to.have.a.property('memory')
@@ -24,7 +41,7 @@ describe('.diag', () => {
2441
})
2542

2643
it('.diag.cmds', (done) => {
27-
apiClients.a.diag.cmds((err, res) => {
44+
ipfs.diag.cmds((err, res) => {
2845
expect(err).to.not.exist
2946
expect(res).to.exist
3047
done()
@@ -33,14 +50,14 @@ describe('.diag', () => {
3350

3451
describe('promise', () => {
3552
it('.diag.net', () => {
36-
return apiClients.a.diag.net()
53+
return ipfs.diag.net()
3754
.then((res) => {
3855
expect(res).to.exist
3956
})
4057
})
4158

4259
it('.diag.sys', () => {
43-
return apiClients.a.diag.sys()
60+
return ipfs.diag.sys()
4461
.then((res) => {
4562
expect(res).to.exist
4663
expect(res).to.have.a.property('memory')
@@ -49,7 +66,7 @@ describe('.diag', () => {
4966
})
5067

5168
it('.diag.cmds', () => {
52-
return apiClients.a.diag.cmds()
69+
return ipfs.diag.cmds()
5370
.then((res) => {
5471
expect(res).to.exist
5572
})

0 commit comments

Comments
 (0)