Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api test] Properly pipe to unique pipe-chains in
.by()
.
- Loading branch information
Showing
4 changed files
with
106 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* filter-stream.js: Simple readable and writable stream that filters key by value. | ||
* | ||
* (C) 2012, Nodejitsu Inc. | ||
* | ||
*/ | ||
|
||
var utile = require('utile'), | ||
ReadWriteStream = require('./read-write-stream') | ||
|
||
// | ||
// ### function ReadWriteStream () | ||
// A aimple readable and writable stream that filters key by value. | ||
// | ||
var FilterStream = module.exports = function FilterStream(key, value) { | ||
this.key = key; | ||
this.value = value | ||
|
||
ReadWriteStream.call(this); | ||
}; | ||
|
||
// | ||
// Inherit from `ReadWriteStream`. | ||
// | ||
utile.inherits(FilterStream, ReadWriteStream); | ||
|
||
// | ||
// ### function write (data) | ||
// Emits the "data" event with the pass-thru `data`. | ||
// | ||
FilterStream.prototype.write = function (data) { | ||
if (data[this.key] === this.value) { | ||
this.emit('data', data); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"service": "charlie/app/health/heartbeat", | ||
"ttl": 50 | ||
}, | ||
{ | ||
"service": "charlie/app/health/memory", | ||
"ttl": 50 | ||
}, | ||
{ | ||
"service": "charlie/app/health/heartbeat", | ||
"ttl": 50 | ||
} | ||
] |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* change-test.js: Tests for the Change reactor stream. | ||
* | ||
* (C) 2012, Nodejitsu Inc. | ||
* | ||
*/ | ||
|
||
var assert = require('assert'), | ||
vows = require('vows'), | ||
godot = require('../../lib/godot'), | ||
macros = require('../macros').reactor; | ||
|
||
var count = 0; | ||
|
||
vows.describe('godot/reactor/by').addBatch({ | ||
"Godot by": { | ||
"service": macros.shouldEmitDataSync( | ||
godot.reactor() | ||
.by( | ||
'service', | ||
godot.reactor().map(function (data) { | ||
count++; | ||
return data; | ||
}) | ||
), | ||
'by', | ||
3 | ||
) | ||
} | ||
}).addBatch({ | ||
"Should emit pipe the events to the correct pipe-chains": function () { | ||
assert.equal(count, 3); | ||
} | ||
}).export(module); |