|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const expect = require('chai').expect |
| 5 | +const series = require('async/series') |
| 6 | +const parallel = require('async/parallel') |
| 7 | +const waterfall = require('async/waterfall') |
| 8 | +const bl = require('bl') |
| 9 | +const crypto = require('crypto') |
| 10 | + |
| 11 | +const GoDaemon = require('./daemons/go') |
| 12 | +const JsDaemon = require('./daemons/js') |
| 13 | + |
| 14 | +describe('interop', () => { |
| 15 | + let goDaemon |
| 16 | + let jsDaemon |
| 17 | + |
| 18 | + before((done) => { |
| 19 | + goDaemon = new GoDaemon() |
| 20 | + jsDaemon = new JsDaemon() |
| 21 | + |
| 22 | + parallel([ |
| 23 | + (cb) => goDaemon.start(cb), |
| 24 | + (cb) => jsDaemon.start(cb) |
| 25 | + ], done) |
| 26 | + }) |
| 27 | + |
| 28 | + after((done) => { |
| 29 | + parallel([ |
| 30 | + (cb) => goDaemon.stop(cb), |
| 31 | + (cb) => jsDaemon.stop(cb) |
| 32 | + ], done) |
| 33 | + }) |
| 34 | + |
| 35 | + it('connect go <-> js', (done) => { |
| 36 | + let jsId |
| 37 | + let goId |
| 38 | + |
| 39 | + series([ |
| 40 | + (cb) => parallel([ |
| 41 | + (cb) => jsDaemon.api.id(cb), |
| 42 | + (cb) => goDaemon.api.id(cb) |
| 43 | + ], (err, ids) => { |
| 44 | + expect(err).to.not.exist |
| 45 | + jsId = ids[0] |
| 46 | + goId = ids[1] |
| 47 | + cb() |
| 48 | + }), |
| 49 | + (cb) => goDaemon.api.swarm.connect(jsId.addresses[0], cb), |
| 50 | + (cb) => jsDaemon.api.swarm.connect(goId.addresses[0], cb), |
| 51 | + (cb) => parallel([ |
| 52 | + (cb) => goDaemon.api.swarm.peers(cb), |
| 53 | + (cb) => jsDaemon.api.swarm.peers(cb) |
| 54 | + ], (err, peers) => { |
| 55 | + expect(err).to.not.exist |
| 56 | + expect(peers[0].map((p) => p.peer.toB58String())).to.include(jsId.id) |
| 57 | + expect(peers[1].map((p) => p.peer.toB58String())).to.include(goId.id) |
| 58 | + cb() |
| 59 | + }) |
| 60 | + ], done) |
| 61 | + }) |
| 62 | + |
| 63 | + it('cat file: go -> js', (done) => { |
| 64 | + const data = crypto.randomBytes(1024 * 5) |
| 65 | + waterfall([ |
| 66 | + (cb) => goDaemon.api.add(data, cb), |
| 67 | + (res, cb) => jsDaemon.api.cat(res[0].hash, cb), |
| 68 | + (stream, cb) => stream.pipe(bl(cb)) |
| 69 | + ], (err, file) => { |
| 70 | + expect(err).to.not.exist |
| 71 | + expect(file).to.be.eql(data) |
| 72 | + done() |
| 73 | + }) |
| 74 | + }) |
| 75 | + |
| 76 | + it('cat file: js -> go', (done) => { |
| 77 | + const data = crypto.randomBytes(1024 * 5) |
| 78 | + waterfall([ |
| 79 | + (cb) => jsDaemon.api.add(data, cb), |
| 80 | + (res, cb) => goDaemon.api.cat(res[0].hash, cb), |
| 81 | + (stream, cb) => stream.pipe(bl(cb)) |
| 82 | + ], (err, file) => { |
| 83 | + expect(err).to.not.exist |
| 84 | + expect(file).to.be.eql(data) |
| 85 | + done() |
| 86 | + }) |
| 87 | + }) |
| 88 | +}) |
0 commit comments