Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit 3f07259

Browse files
committed
fix: incorrect import name Stop -> Hop and making tests pass again
1 parent b08d5bb commit 3f07259

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/circuit/hop.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const once = require('once')
1414
const utilsFactory = require('./utils')
1515
const StreamHandler = require('./stream-handler')
1616
const waterfall = require('async/waterfall')
17+
const assignInWith = require('lodash/assignInWith')
1718

1819
const multicodec = require('./../multicodec')
1920

@@ -33,7 +34,16 @@ class Hop extends EE {
3334
*/
3435
constructor (options) {
3536
super()
36-
this.config = Object.assign({active: false}, options)
37+
this.config = assignInWith(
38+
{
39+
active: false,
40+
enabled: false
41+
},
42+
options,
43+
(orig, src) => {
44+
typeof src === 'undefined' ? false : src
45+
})
46+
3747
this.swarm = null
3848
this.active = this.config.active
3949
}
@@ -98,6 +108,10 @@ class Hop extends EE {
98108
* @return {void}
99109
*/
100110
mount (swarm) {
111+
if (!this.config.enabled) {
112+
return
113+
}
114+
101115
this.swarm = swarm
102116
utils = utilsFactory(swarm)
103117
this.swarm.handle(multicodec.hop, (proto, conn) => {

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
module.exports = {
4-
Stop: require('./circuit/hop'),
4+
Hop: require('./circuit/hop'),
55
Dialer: require('./dialer'),
66
multicodec: require('./multicodec'),
77
tag: 'Circuit'

test/hop.spec.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const expect = require('chai').expect
1919

2020
describe('relay', function () {
2121
describe(`handle circuit requests`, function () {
22-
const relay = sinon.createStubInstance(Hop)
2322
const dialer = sinon.createStubInstance(Dialer)
2423

24+
let relay
2525
let swarm
2626
let fromConn
2727
let toConn
@@ -55,13 +55,9 @@ describe('relay', function () {
5555
cb()
5656
}
5757
], () => {
58-
relay.mount.callThrough()
59-
relay.emit.callThrough()
60-
relay.on.callThrough()
61-
relay._readDstAddr.callThrough()
62-
relay._readSrcAddr.callThrough()
63-
relay._writeErr.callThrough()
58+
relay = new Hop({enabled: true})
6459
relay.mount(swarm) // mount the swarm
60+
relay._circuit = sinon.stub()
6561
relay._circuit.callsArg(3, null, toConn)
6662

6763
dialer.relayConns = new Map()
@@ -71,14 +67,7 @@ describe('relay', function () {
7167
})
7268

7369
afterEach(() => {
74-
relay.mount.reset()
75-
relay.emit.reset()
76-
relay.on.reset()
7770
relay._circuit.reset()
78-
relay._readDstAddr.reset()
79-
relay._readSrcAddr.reset()
80-
relay._readSrcAddr.reset()
81-
dialer.negotiateRelay.reset()
8271
})
8372

8473
it(`handle a valid circuit request`, function (done) {

0 commit comments

Comments
 (0)