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

Commit 959d68d

Browse files
committed
feat: use new ipfsd-ctl
1 parent a90ca29 commit 959d68d

File tree

11 files changed

+421
-414
lines changed

11 files changed

+421
-414
lines changed

src/block.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ function expectKey (block, expected, callback) {
1919

2020
module.exports = (common) => {
2121
describe('.block', () => {
22-
let ipfs
22+
let ipfsd
2323

2424
before(function (done) {
2525
// CI takes longer to instantiate the daemon, so we need to increase the
2626
// timeout for the before step
2727
this.timeout(60 * 1000)
2828

29-
common.setup((err, factory) => {
29+
common.setup((err, df) => {
3030
expect(err).to.not.exist()
31-
factory.spawnNode((err, node) => {
31+
df.spawn((err, node) => {
3232
expect(err).to.not.exist()
33-
ipfs = node
33+
ipfsd = node
3434
done()
3535
})
3636
})
3737
})
3838

39-
after((done) => common.teardown(done))
39+
after((done) => ipfsd.stop(done))
4040

4141
describe('.put', () => {
4242
it('a buffer, using defaults', (done) => {
4343
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
4444
const blob = new Buffer('blorb')
4545

46-
ipfs.block.put(blob, (err, block) => {
46+
ipfsd.api.block.put(blob, (err, block) => {
4747
expect(err).to.not.exist()
4848
expect(block.data).to.be.eql(blob)
4949
expectKey(block, multihash.fromB58String(expectedHash), done)
@@ -55,7 +55,7 @@ module.exports = (common) => {
5555
const cid = new CID(expectedHash)
5656
const blob = new Buffer('blorb')
5757

58-
ipfs.block.put(blob, { cid: cid }, (err, block) => {
58+
ipfsd.api.block.put(blob, { cid: cid }, (err, block) => {
5959
expect(err).to.not.exist()
6060
expect(block.data).to.be.eql(blob)
6161
expectKey(block, multihash.fromB58String(expectedHash), done)
@@ -66,7 +66,7 @@ module.exports = (common) => {
6666
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
6767
const blob = new Buffer('blorb')
6868

69-
ipfs.block.put(blob, {
69+
ipfsd.api.block.put(blob, {
7070
format: 'dag-pb',
7171
mhtype: 'sha2-256',
7272
version: 0
@@ -82,7 +82,7 @@ module.exports = (common) => {
8282
const cid = new CID(expectedHash)
8383
const b = new Block(new Buffer('blorb'), cid)
8484

85-
ipfs.block.put(b, (err, block) => {
85+
ipfsd.api.block.put(b, (err, block) => {
8686
expect(err).to.not.exist()
8787
expect(block.data).to.eql(new Buffer('blorb'))
8888
expectKey(block, multihash.fromB58String(expectedHash), done)
@@ -92,7 +92,7 @@ module.exports = (common) => {
9292
it('error with array of blocks', (done) => {
9393
const blob = Buffer('blorb')
9494

95-
ipfs.block.put([blob, blob], (err) => {
95+
ipfsd.api.block.put([blob, blob], (err) => {
9696
expect(err).to.be.an.instanceof(Error)
9797
done()
9898
})
@@ -106,7 +106,7 @@ module.exports = (common) => {
106106
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
107107
const cid = new CID(hash)
108108

109-
ipfs.block.get(cid, (err, block) => {
109+
ipfsd.api.block.get(cid, (err, block) => {
110110
expect(err).to.not.exist()
111111
expect(block.data).to.eql(new Buffer('blorb'))
112112
expectKey(block, cid.multihash, done)
@@ -116,7 +116,7 @@ module.exports = (common) => {
116116
it('by CID in Str', (done) => {
117117
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
118118

119-
ipfs.block.get(hash, (err, block) => {
119+
ipfsd.api.block.get(hash, (err, block) => {
120120
expect(err).to.not.exist()
121121
expect(block.data).to.eql(new Buffer('blorb'))
122122
expectKey(block, multihash.fromB58String(hash), done)
@@ -131,7 +131,7 @@ module.exports = (common) => {
131131
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
132132
const cid = new CID(hash)
133133

134-
ipfs.block.stat(cid, (err, stats) => {
134+
ipfsd.api.block.stat(cid, (err, stats) => {
135135
expect(err).to.not.exist()
136136
expect(stats).to.have.property('key')
137137
expect(stats).to.have.property('size')

src/config.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,66 @@ chai.use(dirtyChai)
1111
module.exports = (common) => {
1212
describe('.config', function () {
1313
this.timeout(30 * 1000)
14-
let ipfs
14+
let ipfsd
1515

1616
before(function (done) {
1717
// CI takes longer to instantiate the daemon, so we need to increase the
1818
// timeout for the before step
1919
this.timeout(60 * 1000)
2020

21-
common.setup((err, factory) => {
21+
common.setup((err, df) => {
2222
expect(err).to.not.exist()
23-
factory.spawnNode((err, node) => {
23+
df.spawn((err, node) => {
2424
expect(err).to.not.exist()
25-
ipfs = node
25+
ipfsd = node
2626
done()
2727
})
2828
})
2929
})
3030

31-
after((done) => common.teardown(done))
31+
after((done) => ipfsd.stop(done))
3232

3333
describe('.get', () => {
3434
it('retrieve the whole config', (done) => {
35-
ipfs.config.get((err, config) => {
35+
ipfsd.api.config.get((err, config) => {
3636
expect(err).to.not.exist()
3737
expect(config).to.exist()
3838
done()
3939
})
4040
})
4141

4242
it('retrieve a value through a key', (done) => {
43-
ipfs.config.get('Identity.PeerID', (err, peerId) => {
43+
ipfsd.api.config.get('Identity.PeerID', (err, peerId) => {
4444
expect(err).to.not.exist()
4545
expect(peerId).to.exist()
4646
done()
4747
})
4848
})
4949

5050
it('retrieve a value through a nested key', (done) => {
51-
ipfs.config.get('Addresses.Swarm', (err, swarmAddrs) => {
51+
ipfsd.api.config.get('Addresses.Swarm', (err, swarmAddrs) => {
5252
expect(err).to.not.exist()
5353
expect(swarmAddrs).to.exist()
5454
done()
5555
})
5656
})
5757

5858
it('fail on non valid key', (done) => {
59-
ipfs.config.get(1234, (err, peerId) => {
59+
ipfsd.api.config.get(1234, (err, peerId) => {
6060
expect(err).to.exist()
6161
done()
6262
})
6363
})
6464

6565
it('fail on non exist()ent key', (done) => {
66-
ipfs.config.get('Bananas', (err, peerId) => {
66+
ipfsd.api.config.get('Bananas', (err, peerId) => {
6767
expect(err).to.exist()
6868
done()
6969
})
7070
})
7171

7272
it('Promises support', () => {
73-
return ipfs.config.get()
73+
return ipfsd.api.config.get()
7474
.then((config) => {
7575
expect(config).to.exist()
7676
})
@@ -79,9 +79,9 @@ module.exports = (common) => {
7979

8080
describe('.set', () => {
8181
it('set a new key', (done) => {
82-
ipfs.config.set('Fruit', 'banana', (err) => {
82+
ipfsd.api.config.set('Fruit', 'banana', (err) => {
8383
expect(err).to.not.exist()
84-
ipfs.config.get('Fruit', (err, fruit) => {
84+
ipfsd.api.config.get('Fruit', (err, fruit) => {
8585
expect(err).to.not.exist()
8686
expect(fruit).to.equal('banana')
8787
done()
@@ -90,9 +90,9 @@ module.exports = (common) => {
9090
})
9191

9292
it('set an already exist()ing key', (done) => {
93-
ipfs.config.set('Fruit', 'morango', (err) => {
93+
ipfsd.api.config.set('Fruit', 'morango', (err) => {
9494
expect(err).to.not.exist()
95-
ipfs.config.get('Fruit', (err, fruit) => {
95+
ipfsd.api.config.get('Fruit', (err, fruit) => {
9696
expect(err).to.not.exist()
9797
expect(fruit).to.equal('morango')
9898
done()
@@ -103,9 +103,9 @@ module.exports = (common) => {
103103
it('set a JSON object', (done) => {
104104
const key = 'API.HTTPHeaders.Access-Control-Allow-Origin'
105105
const val = ['http://example.io']
106-
ipfs.config.set(key, val, function (err) {
106+
ipfsd.api.config.set(key, val, function (err) {
107107
expect(err).to.not.exist()
108-
ipfs.config.get(key, function (err, result) {
108+
ipfsd.api.config.get(key, function (err, result) {
109109
expect(err).to.not.exist()
110110
expect(result).to.deep.equal(val)
111111
done()
@@ -114,22 +114,22 @@ module.exports = (common) => {
114114
})
115115

116116
it('fail on non valid key', (done) => {
117-
ipfs.config.set(Buffer.from('heeey'), '', (err) => {
117+
ipfsd.api.config.set(Buffer.from('heeey'), '', (err) => {
118118
expect(err).to.exist()
119119
done()
120120
})
121121
})
122122

123123
it('fail on non valid value', (done) => {
124-
ipfs.config.set('Fruit', Buffer.from('abc'), (err) => {
124+
ipfsd.api.config.set('Fruit', Buffer.from('abc'), (err) => {
125125
expect(err).to.exist()
126126
done()
127127
})
128128
})
129129

130130
it('Promises support', () => {
131-
return ipfs.config.set('Fruit', 'banana')
132-
.then(() => ipfs.config.get('Fruit'))
131+
return ipfsd.api.config.set('Fruit', 'banana')
132+
.then(() => ipfsd.api.config.get('Fruit'))
133133
.then((fruit) => {
134134
expect(fruit).to.equal('banana')
135135
})
@@ -145,19 +145,19 @@ module.exports = (common) => {
145145
}
146146

147147
it('replace the whole config', (done) => {
148-
ipfs.config.replace(config, (err) => {
148+
ipfsd.api.config.replace(config, (err) => {
149149
expect(err).to.not.exist()
150-
ipfs.config.get((err, _config) => {
150+
ipfsd.api.config.get((err, _config) => {
151151
expect(err).to.not.exist()
152152
expect(_config).to.deep.equal(config)
153153
})
154154
})
155155
})
156156

157157
it('replace to empty config', (done) => {
158-
ipfs.config.replace({}, (err) => {
158+
ipfsd.api.config.replace({}, (err) => {
159159
expect(err).to.not.exist()
160-
ipfs.config.get((err, _config) => {
160+
ipfsd.api.config.get((err, _config) => {
161161
expect(err).to.not.exist()
162162
expect(_config).to.deep.equal(config)
163163
})

0 commit comments

Comments
 (0)