|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const expect = require('chai').expect |
| 5 | + |
| 6 | +module.exports = (common) => { |
| 7 | + describe('.config', () => { |
| 8 | + let ipfs |
| 9 | + |
| 10 | + before((done) => { |
| 11 | + common.setup((err, _ipfs) => { |
| 12 | + expect(err).to.not.exist |
| 13 | + ipfs = _ipfs |
| 14 | + done() |
| 15 | + }) |
| 16 | + }) |
| 17 | + |
| 18 | + after((done) => { |
| 19 | + common.teardown(done) |
| 20 | + }) |
| 21 | + |
| 22 | + describe('callback API', () => { |
| 23 | + describe('.get', () => { |
| 24 | + it('retrieve the whole config', (done) => { |
| 25 | + ipfs.config.get((err, config) => { |
| 26 | + expect(err).to.not.exist |
| 27 | + expect(config).to.exist |
| 28 | + done() |
| 29 | + }) |
| 30 | + }) |
| 31 | + |
| 32 | + it('retrieve a value through a key', (done) => { |
| 33 | + ipfs.config.get('Identity', (err, identity) => { |
| 34 | + expect(err).to.not.exist |
| 35 | + expect(identity).to.exist |
| 36 | + done() |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + it('retrieve a value through a nested key', (done) => { |
| 41 | + ipfs.config.get('Addresses.Swarm', (err, swarmAddrs) => { |
| 42 | + expect(err).to.not.exist |
| 43 | + expect(swarmAddrs).to.exist |
| 44 | + done() |
| 45 | + }) |
| 46 | + }) |
| 47 | + |
| 48 | + it('fail on non valid key', (done) => { |
| 49 | + ipfs.config.get(1234, (err, peerId) => { |
| 50 | + expect(err).to.exist |
| 51 | + done() |
| 52 | + }) |
| 53 | + }) |
| 54 | + |
| 55 | + it('fail on non existent key', (done) => { |
| 56 | + ipfs.config.get('Bananas', (err, peerId) => { |
| 57 | + expect(err).to.exist |
| 58 | + done() |
| 59 | + }) |
| 60 | + }) |
| 61 | + }) |
| 62 | +https://github.com/ipfs/go-ipfs/issues/2927 |
| 63 | + describe('.set', () => { |
| 64 | + it('set a new key', (done) => { |
| 65 | + ipfs.config.set('Fruit', 'banana', (err) => { |
| 66 | + expect(err).to.not.exist |
| 67 | + ipfs.config.get('Fruit', (err, fruit) => { |
| 68 | + expect(err).to.not.exist |
| 69 | + expect(fruit).to.equal('banana') |
| 70 | + done() |
| 71 | + }) |
| 72 | + }) |
| 73 | + }) |
| 74 | + |
| 75 | + it('set an already existing key', (done) => { |
| 76 | + ipfs.config.set('Fruit', 'morango', (err) => { |
| 77 | + expect(err).to.not.exist |
| 78 | + ipfs.config.get('Fruit', (err, fruit) => { |
| 79 | + expect(err).to.not.exist |
| 80 | + expect(fruit).to.equal('morango') |
| 81 | + done() |
| 82 | + }) |
| 83 | + }) |
| 84 | + }) |
| 85 | + |
| 86 | + it('set a json object', (done) => { |
| 87 | + const key = 'API.HTTPHeaders.Access-Control-Allow-Origin' |
| 88 | + const val = ['http://example.io'] |
| 89 | + ipfs.config.set(key, val, function (err) { |
| 90 | + expect(err).to.not.exist |
| 91 | + ipfs.config.get(key, function (err, result) { |
| 92 | + expect(err).to.not.exist |
| 93 | + expect(result).to.deep.equal(val) |
| 94 | + done() |
| 95 | + }) |
| 96 | + }) |
| 97 | + }) |
| 98 | + |
| 99 | + it('fail on non valid key', (done) => { |
| 100 | + ipfs.config.set(new Buffer('heeey'), '', (err) => { |
| 101 | + expect(err).to.exist |
| 102 | + done() |
| 103 | + }) |
| 104 | + }) |
| 105 | + |
| 106 | + it('fail on non valid value', (done) => { |
| 107 | + ipfs.config.set('Fruit', new Buffer('abc'), (err) => { |
| 108 | + expect(err).to.exist |
| 109 | + done() |
| 110 | + }) |
| 111 | + }) |
| 112 | + }) |
| 113 | + |
| 114 | + // Waiting for fix on go-ipfs |
| 115 | + // - https://github.com/ipfs/js-ipfs-api/pull/307#discussion_r69281789 |
| 116 | + // - https://github.com/ipfs/go-ipfs/issues/2927 |
| 117 | + describe.skip('.replace', () => { |
| 118 | + const config = { |
| 119 | + Fruit: 'Bananas' |
| 120 | + } |
| 121 | + |
| 122 | + it('replace the whole config', (done) => { |
| 123 | + ipfs.config.replace(config, (err) => { |
| 124 | + expect(err).to.not.exist |
| 125 | + ipfs.config.get((err, _config) => { |
| 126 | + expect(err).to.not.exist |
| 127 | + expect(_config).to.deep.equal(config) |
| 128 | + }) |
| 129 | + }) |
| 130 | + }) |
| 131 | + |
| 132 | + it('replace to empty config', (done) => { |
| 133 | + ipfs.config.replace({}, (err) => { |
| 134 | + expect(err).to.not.exist |
| 135 | + ipfs.config.get((err, _config) => { |
| 136 | + expect(err).to.not.exist |
| 137 | + expect(_config).to.deep.equal(config) |
| 138 | + }) |
| 139 | + }) |
| 140 | + }) |
| 141 | + }) |
| 142 | + }) |
| 143 | + describe('promise API', () => {}) |
| 144 | + }) |
| 145 | +} |
0 commit comments