191 lines
4.9 KiB
JavaScript
Raw Normal View History

2015-07-10 22:02:57 -07:00
var streamPair = require('stream-pair')
2015-07-10 18:47:43 -07:00
module.exports.all = function (test, common) {
2015-07-10 22:02:57 -07:00
test('Open a stream from the dealer', function (t) {
common.setup(test, function (err, Muxer) {
t.plan(4)
2015-07-10 18:47:43 -07:00
t.ifError(err, 'Should not throw')
2015-07-10 22:02:57 -07:00
var pair = streamPair.create()
var dialer = new Muxer()
var listener = new Muxer()
2015-07-14 16:43:20 -07:00
var connDialer = dialer.attach(pair, false)
var connListener = listener.attach(pair.other, true)
2015-07-10 22:02:57 -07:00
connDialer.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream')
})
connListener.on('stream', function (stream) {
t.pass('got stream')
})
2015-07-10 18:47:43 -07:00
})
})
2015-07-10 22:02:57 -07:00
test('Open a stream from the listener', function (t) {
common.setup(test, function (err, Muxer) {
t.plan(4)
t.ifError(err, 'Should not throw')
var pair = streamPair.create()
var dialer = new Muxer()
var listener = new Muxer()
2015-07-14 16:43:20 -07:00
var connDialer = dialer.attach(pair, false)
var connListener = listener.attach(pair.other, true)
2015-07-10 22:02:57 -07:00
connListener.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream')
})
connDialer.on('stream', function (stream) {
t.pass('got stream')
})
})
})
2015-07-14 19:04:18 -07:00
test('Open a stream on both sides', function (t) {
common.setup(test, function (err, Muxer) {
t.plan(7)
t.ifError(err, 'Should not throw')
var pair = streamPair.create()
var dialer = new Muxer()
var listener = new Muxer()
var connDialer = dialer.attach(pair, false)
var connListener = listener.attach(pair.other, true)
connDialer.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream from dialer')
})
connListener.on('stream', function (stream) {
t.pass('listener got stream')
})
connListener.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream from listener')
})
connDialer.on('stream', function (stream) {
t.pass('dialer got stream')
})
})
})
2015-07-22 13:00:10 -07:00
test('Open a stream on one side, write, open a stream in the other side', function (t) {
common.setup(test, function (err, Muxer) {
t.plan(9)
t.ifError(err, 'Should not throw')
var pair = streamPair.create()
var dialer = new Muxer()
var listener = new Muxer()
var connDialer = dialer.attach(pair, false)
var connListener = listener.attach(pair.other, true)
connDialer.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream from dialer')
stream.write('hey')
})
connListener.on('stream', function (stream) {
t.pass('listener got stream')
stream.on('data', function (chunk) {
t.equal(chunk.toString(), 'hey')
})
connListener.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream from listener')
stream.write('hello')
})
})
connDialer.on('stream', function (stream) {
t.pass('dialer got stream')
stream.on('data', function (chunk) {
t.equal(chunk.toString(), 'hello')
})
})
})
})
test('Open a stream using the net.connect pattern', function (t) {
common.setup(test, function (err, Muxer) {
t.plan(3)
t.ifError(err, 'Should not throw')
var pair = streamPair.create()
var dialer = new Muxer()
var listener = new Muxer()
2015-07-14 16:43:20 -07:00
var connDialer = dialer.attach(pair, false)
var connListener = listener.attach(pair.other, true)
var stream = connListener.dialStream()
stream.on('ready', function () {
t.pass('dialed stream')
})
stream.on('error', function (err) {
t.ifError(err, 'Should not throw')
})
connDialer.on('stream', function (stream) {
t.pass('got stream')
})
})
})
test('Buffer writes Open a stream using the net.connect pattern', function (t) {
common.setup(test, function (err, Muxer) {
t.plan(4)
t.ifError(err, 'Should not throw')
var pair = streamPair.create()
var dialer = new Muxer()
var listener = new Muxer()
2015-07-14 16:43:20 -07:00
var connDialer = dialer.attach(pair, false)
var connListener = listener.attach(pair.other, true)
var stream = connListener.dialStream()
stream.write('buffer this')
stream.on('ready', function () {
t.pass('dialed stream')
})
stream.on('error', function (err) {
t.ifError(err, 'Should not throw')
})
connDialer.on('stream', function (stream) {
t.pass('got stream')
stream.on('data', function (chunk) {
t.equal(chunk.toString(), 'buffer this')
})
})
})
})
2015-07-10 18:47:43 -07:00
}