This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Improving test coverage #6
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ca13950
Improving test coverage
vsukhomlinov b739631
removing console.log
vsukhomlinov f42b93f
Checking socket closing case, removing socket closure from handler code
vsukhomlinov 4fdb875
Merge remote-tracking branch 'upstream/master'
vsukhomlinov cab6a34
updating travis to fix buffertools installation
vsukhomlinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
var Lab = require('lab') | ||
var Code = require('code') | ||
var lab = exports.lab = Lab.script() | ||
var lpm = require('length-prefixed-message') | ||
var PROTOCOLID = require('../../src/lib/protocol-id') | ||
|
||
var experiment = lab.experiment | ||
var test = lab.test | ||
|
@@ -29,12 +31,40 @@ experiment('Node.js Implementation: ', function () { | |
done() | ||
}) | ||
|
||
test('create a Broadcast MultiStream via utility function', function (done) { | ||
expect(MultiStream.Broadcast.createBroadcast()).to.be.an.instanceof(MultiStream.Broadcast) | ||
done() | ||
}) | ||
|
||
test('throw an error if Broadcast function is misused', function (done) { | ||
try { | ||
MultiStream.Broadcast() | ||
} catch (e) { | ||
expect(e.message).to.equal('Broadcast must be called with new, or used with Broadcast') | ||
done() | ||
} | ||
}) | ||
|
||
test('create a Silent MultiStream()', function (done) { | ||
msS = new MultiStream.Silent() | ||
expect(msS).to.be.an.instanceof(MultiStream.Silent) | ||
done() | ||
}) | ||
|
||
test('create a Silent MultiStream via utility function', function (done) { | ||
expect(MultiStream.Silent.createSilent()).to.be.an.instanceof(MultiStream.Silent) | ||
done() | ||
}) | ||
|
||
test('throw an error if Silent function is misused', function (done) { | ||
try { | ||
MultiStream.Silent() | ||
} catch (e) { | ||
expect(e.message).to.equal('Silent must be called with new, or used with Silent') | ||
done() | ||
} | ||
}) | ||
|
||
test('attach a stream to Broadcast MultiStream (tcp server)', function (done) { | ||
tcp.createServer(function (socket) { | ||
msB.handle(socket) | ||
|
@@ -68,4 +98,35 @@ experiment('Node.js Implementation: ', function () { | |
|
||
}) | ||
|
||
test('closing socket for unsupported protocol', function (done) { | ||
var acc = new MultiStream.Silent() | ||
tcp.createServer(function (socket) { | ||
acc.handle(socket, function (err) { | ||
expect(err.message).to.equal('Received non supported MultiStream version /garbage/1.0.0') | ||
done() | ||
}) | ||
}).listen(8021) | ||
|
||
var socket = tcp.connect({port: 8021}, function tcpConnectionOpen () { | ||
lpm.write(socket, '/garbage/1.0.0\n') | ||
}) | ||
}) | ||
|
||
test('closing socket for unsupported handler', function (done) { | ||
var acc = new MultiStream.Silent() | ||
tcp.createServer(function (socket) { | ||
acc.handle(socket, function () { | ||
acc.addHandler('/none/1.2.3', function (err) { | ||
expect(err.message).to.equal('Received non supported Protocol or Version: /none/1.0.0') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not be up to the protocol handler each time there is an attempt to handshake a protocol that isn't itself. Several protocol handlers might be added to the same connection |
||
done() | ||
}) | ||
}) | ||
}).listen(8022) | ||
|
||
var socket = tcp.connect({port: 8022}, function tcpConnectionOpen () { | ||
lpm.write(socket, PROTOCOLID + '\n') | ||
lpm.write(socket, '/none/1.0.0\n') | ||
}) | ||
}) | ||
|
||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is the check to see if the socket is closed?