|
| 1 | +/* eslint-env mocha */ |
| 2 | + |
| 3 | +const expect = require('chai').expect |
| 4 | +const nexpect = require('nexpect') |
| 5 | +const httpAPI = require('../../src/http-api') |
| 6 | + |
| 7 | +describe('block', () => { |
| 8 | + describe('api offline', () => { |
| 9 | + it('put', (done) => { |
| 10 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'put', process.cwd() + '/test/test-data/hello']) |
| 11 | + .run((err, stdout, exitcode) => { |
| 12 | + expect(err).to.not.exist |
| 13 | + expect(exitcode).to.equal(0) |
| 14 | + expect(stdout[0]) |
| 15 | + .to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') |
| 16 | + done() |
| 17 | + }) |
| 18 | + }) |
| 19 | + |
| 20 | + it('get', (done) => { |
| 21 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'get', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) |
| 22 | + .run((err, stdout, exitcode) => { |
| 23 | + expect(err).to.not.exist |
| 24 | + expect(exitcode).to.equal(0) |
| 25 | + expect(stdout[0]) |
| 26 | + .to.equal('hello world') |
| 27 | + done() |
| 28 | + }) |
| 29 | + }) |
| 30 | + |
| 31 | + it('stat', (done) => { |
| 32 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'stat', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) |
| 33 | + .run((err, stdout, exitcode) => { |
| 34 | + expect(err).to.not.exist |
| 35 | + expect(exitcode).to.equal(0) |
| 36 | + expect(stdout[0]) |
| 37 | + .to.equal('Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') |
| 38 | + expect(stdout[1]) |
| 39 | + .to.equal('Size: 12') |
| 40 | + done() |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + it('rm', (done) => { |
| 45 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'rm', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) |
| 46 | + .run((err, stdout, exitcode) => { |
| 47 | + expect(err).to.not.exist |
| 48 | + expect(exitcode).to.equal(0) |
| 49 | + expect(stdout[0]) |
| 50 | + .to.equal('removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') |
| 51 | + done() |
| 52 | + }) |
| 53 | + }) |
| 54 | + }) |
| 55 | + |
| 56 | + describe('api running', () => { |
| 57 | + before((done) => { |
| 58 | + httpAPI.start((err) => { |
| 59 | + expect(err).to.not.exist |
| 60 | + done() |
| 61 | + }) |
| 62 | + }) |
| 63 | + |
| 64 | + after((done) => { |
| 65 | + httpAPI.stop((err) => { |
| 66 | + expect(err).to.not.exist |
| 67 | + done() |
| 68 | + }) |
| 69 | + }) |
| 70 | + |
| 71 | + it('put', (done) => { |
| 72 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'put', process.cwd() + '/test/test-data/hello']) |
| 73 | + .run((err, stdout, exitcode) => { |
| 74 | + expect(err).to.not.exist |
| 75 | + expect(exitcode).to.equal(0) |
| 76 | + expect(stdout[0]) |
| 77 | + .to.equal('QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') |
| 78 | + done() |
| 79 | + }) |
| 80 | + }) |
| 81 | + |
| 82 | + it('get', (done) => { |
| 83 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'get', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) |
| 84 | + .run((err, stdout, exitcode) => { |
| 85 | + expect(err).to.not.exist |
| 86 | + expect(exitcode).to.equal(0) |
| 87 | + expect(stdout[0]) |
| 88 | + .to.equal('hello world') |
| 89 | + done() |
| 90 | + }) |
| 91 | + }) |
| 92 | + |
| 93 | + it('stat', (done) => { |
| 94 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'stat', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) |
| 95 | + .run((err, stdout, exitcode) => { |
| 96 | + expect(err).to.not.exist |
| 97 | + expect(exitcode).to.equal(0) |
| 98 | + expect(stdout[0]) |
| 99 | + .to.equal('Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') |
| 100 | + expect(stdout[1]) |
| 101 | + .to.equal('Size: 12') |
| 102 | + done() |
| 103 | + }) |
| 104 | + }) |
| 105 | + |
| 106 | + it.skip('rm', (done) => { |
| 107 | + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'block', 'rm', 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp']) |
| 108 | + .run((err, stdout, exitcode) => { |
| 109 | + expect(err).to.not.exist |
| 110 | + expect(exitcode).to.equal(0) |
| 111 | + expect(stdout[0]) |
| 112 | + .to.equal('removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') |
| 113 | + done() |
| 114 | + }) |
| 115 | + }) |
| 116 | + }) |
| 117 | +}) |
0 commit comments