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

Commit e000da1

Browse files
committed
follow interface-ipfs-core config spec
1 parent ad51062 commit e000da1

File tree

2 files changed

+24
-136
lines changed

2 files changed

+24
-136
lines changed

src/api/config.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
'use strict'
22

3-
const argCommand = require('../cmd-helpers').argCommand
4-
53
module.exports = (send) => {
64
return {
7-
get: argCommand(send, 'config'),
5+
get: (key, callback) => {
6+
if (typeof key === 'function') {
7+
callback = key
8+
key = undefined
9+
}
10+
11+
if (!key) {
12+
return send('config/show', null, null, null, true, callback)
13+
}
14+
15+
return send('config', key, null, null, callback)
16+
},
817
set (key, value, opts, cb) {
918
if (typeof (opts) === 'function') {
1019
cb = opts
@@ -21,9 +30,6 @@ module.exports = (send) => {
2130

2231
return send('config', [key, value], opts, null, cb)
2332
},
24-
show (cb) {
25-
return send('config/show', null, null, null, true, cb)
26-
},
2733
replace (file, cb) {
2834
return send('config/replace', null, null, file, cb)
2935
}

test/api/config.spec.js

Lines changed: 12 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,15 @@
22
/* globals apiClients */
33
'use strict'
44

5-
const expect = require('chai').expect
6-
const isNode = require('detect-node')
7-
const path = require('path')
8-
9-
describe('.config', () => {
10-
describe('.config.{set, get}', () => {
11-
it('string', (done) => {
12-
const confKey = 'arbitraryKey'
13-
const confVal = 'arbitraryVal'
14-
15-
apiClients.a.config.set(confKey, confVal, (err, res) => {
16-
expect(err).to.not.exist
17-
apiClients.a.config.get(confKey, (err, res) => {
18-
expect(err).to.not.exist
19-
expect(res).to.have.a.property('Value', confVal)
20-
done()
21-
})
22-
})
23-
})
24-
25-
it('bool', (done) => {
26-
const confKey = 'otherKey'
27-
const confVal = true
28-
29-
apiClients.a.config.set(confKey, confVal, (err, res) => {
30-
expect(err).to.not.exist
31-
apiClients.a.config.get(confKey, (err, res) => {
32-
expect(err).to.not.exist
33-
expect(res.Value).to.deep.equal(confVal)
34-
done()
35-
})
36-
})
37-
})
38-
39-
it('json', (done) => {
40-
const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin'
41-
const confVal = ['http://example.io']
42-
43-
apiClients.a.config.set(confKey, confVal, (err, res) => {
44-
expect(err).to.not.exist
45-
apiClients.a.config.get(confKey, (err, res) => {
46-
expect(err).to.not.exist
47-
expect(res.Value).to.deep.equal(confVal)
48-
done()
49-
})
50-
})
51-
})
52-
})
53-
54-
it('.config.show', (done) => {
55-
apiClients.c.config.show((err, res) => {
56-
expect(err).to.not.exist
57-
expect(res).to.exist
58-
done()
59-
})
60-
})
61-
62-
it('.config.replace', (done) => {
63-
if (!isNode) {
64-
return done()
65-
}
66-
67-
apiClients.c.config.replace(path.join(__dirname, '/../r-config.json'), (err, res) => {
68-
expect(err).to.not.exist
69-
expect(res).to.be.equal(null)
70-
done()
71-
})
72-
})
73-
74-
describe('promise', () => {
75-
describe('.config.{set, get}', () => {
76-
it('string', () => {
77-
const confKey = 'arbitraryKey'
78-
const confVal = 'arbitraryVal'
79-
80-
return apiClients.a.config.set(confKey, confVal)
81-
.then((res) => {
82-
return apiClients.a.config.get(confKey)
83-
})
84-
.then((res) => {
85-
expect(res).to.have.a.property('Value', confVal)
86-
})
87-
})
88-
89-
it('bool', () => {
90-
const confKey = 'otherKey'
91-
const confVal = true
92-
93-
return apiClients.a.config.set(confKey, confVal)
94-
.then((res) => {
95-
return apiClients.a.config.get(confKey)
96-
})
97-
.then((res) => {
98-
expect(res.Value).to.deep.equal(confVal)
99-
})
100-
})
101-
102-
it('json', () => {
103-
const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin'
104-
const confVal = ['http://example.com']
105-
106-
return apiClients.a.config.set(confKey, confVal)
107-
.then((res) => {
108-
return apiClients.a.config.get(confKey)
109-
})
110-
.then((res) => {
111-
expect(res.Value).to.deep.equal(confVal)
112-
})
113-
})
114-
})
115-
116-
it('.config.show', () => {
117-
return apiClients.c.config.show()
118-
.then((res) => {
119-
expect(res).to.exist
120-
})
121-
})
122-
123-
it('.config.replace', () => {
124-
if (!isNode) {
125-
return
126-
}
127-
128-
return apiClients.c.config.replace(path.join(__dirname, '/../r-config.json'))
129-
.then((res) => {
130-
expect(res).to.be.equal(null)
131-
})
132-
})
133-
})
134-
})
5+
const test = require('interface-ipfs-core')
6+
7+
const common = {
8+
setup: function (cb) {
9+
cb(null, apiClients.a)
10+
},
11+
teardown: function (cb) {
12+
cb()
13+
}
14+
}
15+
16+
test.config(common)

0 commit comments

Comments
 (0)