Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d177d01

Browse files
authored
Merge pull request #494 from ipfs/fix/less-skipping
Less skipped tests
2 parents a195be6 + be6f679 commit d177d01

File tree

10 files changed

+81
-106
lines changed

10 files changed

+81
-106
lines changed

src/cli/commands/config.js

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict'
22

33
const debug = require('debug')
4-
const get = require('lodash.get')
5-
const set = require('lodash.set')
64
const log = debug('cli:config')
75
log.error = debug('cli:config:error')
86
const utils = require('../utils')
@@ -43,26 +41,17 @@ module.exports = {
4341

4442
if (!value) {
4543
// Get the value of a given key
46-
47-
if (utils.isDaemonOn()) {
48-
return ipfs.config.get(key, (err, config) => {
49-
if (err) {
50-
log.error(err)
51-
throw new Error('failed to read the config')
52-
}
53-
54-
console.log(config.Value)
55-
})
56-
}
57-
58-
ipfs.config.get((err, config) => {
44+
ipfs.config.get(key, (err, value) => {
5945
if (err) {
6046
log.error(err)
6147
throw new Error('failed to read the config')
6248
}
6349

64-
const value = get(config, key)
65-
console.log(value)
50+
if (typeof value === 'object') {
51+
console.log(JSON.stringify(value, null, 2))
52+
} else {
53+
console.log(value)
54+
}
6655
})
6756
} else {
6857
// Set the new value of a given key
@@ -78,28 +67,11 @@ module.exports = {
7867
}
7968
}
8069

81-
if (utils.isDaemonOn()) {
82-
return ipfs.config.set(key, value, (err) => {
83-
if (err) {
84-
log.error(err)
85-
throw new Error('failed to save the config')
86-
}
87-
})
88-
}
89-
90-
ipfs.config.get((err, originalConfig) => {
70+
ipfs.config.set(key, value, (err) => {
9171
if (err) {
9272
log.error(err)
9373
throw new Error('failed to read the config')
9474
}
95-
96-
const updatedConfig = set(originalConfig, key, value)
97-
ipfs.config.replace(updatedConfig, (err) => {
98-
if (err) {
99-
log.error(err)
100-
throw new Error('failed to save the config')
101-
}
102-
})
10375
})
10476
}
10577
})

src/cli/commands/version.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ module.exports = {
3737
throw err
3838
}
3939

40-
if (typeof version === 'object') { // js-ipfs-api output
41-
version = version.Version
42-
}
43-
44-
console.log(`js-ipfs version: ${version}`)
40+
console.log(`js-ipfs version: ${version.version}`)
4541
})
4642
})
4743
}

src/http-api/resources/config.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ exports.getOrSet = {
5757
handler: (request, reply) => {
5858
const key = request.pre.args.key
5959
const value = request.pre.args.value
60+
const ipfs = request.server.app.ipfs
6061

61-
if (typeof value === 'object' && value.type === 'Buffer') {
62+
if (typeof value === 'object' &&
63+
value.type === 'Buffer') {
6264
return reply({
6365
Message: 'Invalid value type',
6466
Code: 0
@@ -67,7 +69,7 @@ exports.getOrSet = {
6769

6870
if (value === undefined) {
6971
// Get the value of a given key
70-
return request.server.app.ipfs.config.get((err, config) => {
72+
return ipfs.config.get((err, config) => {
7173
if (err) {
7274
log.error(err)
7375
return reply({
@@ -89,9 +91,20 @@ exports.getOrSet = {
8991
Value: value
9092
})
9193
})
92-
} else {
93-
// Set the new value of a given key
94-
request.server.app.ipfs.config.get((err, originalConfig) => {
94+
}
95+
96+
// Set the new value of a given key
97+
ipfs.config.get((err, originalConfig) => {
98+
if (err) {
99+
log.error(err)
100+
return reply({
101+
Message: 'Failed to get config value: ' + err,
102+
Code: 0
103+
}).code(500)
104+
}
105+
106+
const updatedConfig = set(originalConfig, key, value)
107+
ipfs.config.replace(updatedConfig, (err) => {
95108
if (err) {
96109
log.error(err)
97110
return reply({
@@ -100,28 +113,37 @@ exports.getOrSet = {
100113
}).code(500)
101114
}
102115

103-
const updatedConfig = set(originalConfig, key, value)
104-
request.server.app.ipfs.config.replace(updatedConfig, (err) => {
105-
if (err) {
106-
log.error(err)
107-
return reply({
108-
Message: 'Failed to get config value: ' + err,
109-
Code: 0
110-
}).code(500)
111-
}
112-
113-
return reply({
114-
Key: key,
115-
Value: value
116-
})
116+
return reply({
117+
Key: key,
118+
Value: value
117119
})
118120
})
119-
}
121+
})
120122
}
121123
}
122124

123125
exports.get = (request, reply) => {
124-
return request.server.app.ipfs.config.get((err, config) => {
126+
const ipfs = request.server.app.ipfs
127+
128+
ipfs.config.get((err, config) => {
129+
if (err) {
130+
log.error(err)
131+
return reply({
132+
Message: 'Failed to get config value: ' + err,
133+
Code: 0
134+
}).code(500)
135+
}
136+
137+
return reply({
138+
Value: config
139+
})
140+
})
141+
}
142+
143+
exports.show = (request, reply) => {
144+
const ipfs = request.server.app.ipfs
145+
146+
ipfs.config.get((err, config) => {
125147
if (err) {
126148
log.error(err)
127149
return reply({

src/http-api/resources/version.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ const boom = require('boom')
55
exports = module.exports
66

77
exports.get = (request, reply) => {
8-
request.server.app.ipfs.version((err, version) => {
8+
const ipfs = request.server.app.ipfs
9+
10+
ipfs.version((err, version) => {
911
if (err) {
1012
return reply(boom.badRequest(err))
1113
}
1214

13-
reply(version)
15+
reply({
16+
Version: version.version,
17+
Commit: version.commit,
18+
Repo: version.repo
19+
})
1420
})
1521
}

src/http-api/routes/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = (server) => {
1919
api.route({
2020
method: '*',
2121
path: '/api/v0/config/show',
22-
handler: resources.config.get
22+
handler: resources.config.show
2323
})
2424

2525
api.route({

test/cli/test-config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,14 @@ describe('config', () => {
123123
})
124124

125125
after((done) => {
126-
console.log('stopping')
127126
httpAPI.stop((err) => {
128-
console.log('stopped')
129127
expect(err).to.not.exist
130128
done()
131129
})
132130
})
133131

134132
describe('get/set', () => {
135-
it.skip('get a config key value', (done) => {
133+
it('get a config key value', (done) => {
136134
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'config', 'Identity.PeerID'], {env})
137135
.run((err, stdout, exitcode) => {
138136
const expected = 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A'

test/cli/test-id.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,16 @@ describe('id', () => {
1212
env.IPFS_PATH = repoPath
1313

1414
describe('api offline', () => {
15-
it.skip('get the id', (done) => {
15+
it('get the id', (done) => {
1616
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'], {env})
1717
.run((err, stdout, exitcode) => {
18-
expect(
19-
stdout
20-
).to.be.eql([
21-
'{',
22-
' "ID": "QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A",',
23-
' "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=",',
24-
' "Addresses": [',
25-
' "/ip4/127.0.0.1/tcp/9990/ws",',
26-
' "/ip4/127.0.0.1/tcp/9999"',
27-
' ],',
28-
' "AgentVersion": "js-ipfs",',
29-
' "ProtocolVersion": "9000"',
30-
'}'
31-
])
32-
3318
expect(err).to.not.exist
3419
expect(exitcode).to.equal(0)
20+
21+
const id = JSON.parse(stdout.join(''))
22+
expect(id).to.have.property('id')
23+
expect(id).to.have.property('publicKey')
24+
expect(id).to.have.property('addresses')
3525
done()
3626
})
3727
})
@@ -55,26 +45,17 @@ describe('id', () => {
5545
})
5646
})
5747

58-
it.skip('get the id', (done) => {
48+
it('get the id', (done) => {
5949
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'], {env})
6050
.run((err, stdout, exitcode) => {
61-
expect(
62-
stdout
63-
).to.be.eql([
64-
'{',
65-
' "ID": "QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A",',
66-
' "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=",',
67-
' "Addresses": [',
68-
' "/ip4/127.0.0.1/tcp/9990/ws",',
69-
' "/ip4/127.0.0.1/tcp/9999"',
70-
' ],',
71-
' "AgentVersion": "js-ipfs",',
72-
' "ProtocolVersion": "9000"',
73-
'}'
74-
])
75-
7651
expect(err).to.not.exist
7752
expect(exitcode).to.equal(0)
53+
54+
const id = JSON.parse(stdout.join(''))
55+
expect(id).to.have.property('id')
56+
expect(id).to.have.property('publicKey')
57+
expect(id).to.have.property('addresses')
58+
7859
done()
7960
})
8061
})

test/cli/test-version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('version', () => {
1212
const env = _.clone(process.env)
1313
env.IPFS_PATH = repoPath
1414

15-
describe.skip('api offline', () => {
15+
describe('api offline', () => {
1616
it('get the version', (done) => {
1717
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'], {env})
1818
.run((err, stdout, exitcode) => {
@@ -24,7 +24,7 @@ describe('version', () => {
2424
})
2525
})
2626

27-
describe.skip('api running', () => {
27+
describe('api running', () => {
2828
let httpAPI
2929

3030
before((done) => {

test/http-api/inject/test-version.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ module.exports = (http) => {
1717
method: 'GET',
1818
url: '/api/v0/version'
1919
}, (res) => {
20-
expect(res.result.version).to.equal(pkgversion)
21-
expect(res.result).to.have.a.property('commit')
22-
expect(res.result).to.have.a.property('repo')
20+
expect(res.result).to.have.a.property('Version', pkgversion)
21+
expect(res.result).to.have.a.property('Commit')
22+
expect(res.result).to.have.a.property('Repo')
2323
done()
2424
})
2525
})

test/http-api/ipfs-api/test-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ module.exports = (ctl) => {
6060
it('.get updatedConfig', (done) => {
6161
ctl.config.get((err, config) => {
6262
expect(err).not.to.exist
63-
expect(config).to.deep.equal(updatedConfig())
63+
expect(config).to.be.eql(updatedConfig())
6464
done()
6565
})
6666
})
6767

6868
// This one is one stale mode till go-ipfs decides
6969
// what to do
70-
describe.skip('.replace', () => {
70+
describe('.replace', () => {
7171
it('returns error if the config is invalid', (done) => {
7272
const filePath = 'test/test-data/badconfig'
7373

0 commit comments

Comments
 (0)