Skip to content

Instantly share code, notes, and snippets.

View gerad's full-sized avatar

Gerad Suyderhoud gerad

View GitHub Profile
console.log("hello")

Vim Notes

copy to mac clipboard

:w !pbcopy

paste from mac clibpoard

var assert = require('assert');
var contracts = require('contracts'); // our home-built contract testing library
var echo = require('./echo_consumer');
// test the echo consumer
var stubConnection = contracts.connection();
echo(stubConnection, 'echo', function(response) {
assert.equal(response, 'echo');
});
stubConnection.testContract("echo-contract.json", { as: "consumer" });
package echo
import (
"testing"
"contracts" // our home-built contract testing library
)
// test the echo provider
func TestEchoProvider(t *testing.T) {
stubConnection := contracts.NewStubConnection()
package echo
type Connection interface {
Subscribe(string, func(string))
Publish(string, string)
}
// echo back any message sent to the "/echo" topic
func StartEchoProvider(connection Connection) {
connection.Subscribe("/echo", func(message string) {
// publish `message` to the "/echo" topic, and call `callback` on response
module.exports = function echo(connection, message, callback) {
connection.subscribe('/echo', callback);
connection.publish('/echo', message);
};
[
{
"source": "consumer",
"topic": "/echo",
"payload": "echo"
},
{
"source": "provider",
"topic": "/echo",
"payload": "echo"
@gerad
gerad / echo-contract.json
Last active August 29, 2015 14:20
Example of using contracts to perform integration testing in a pubsub microservices architecture.
[
{
"source": "consumer",
"topic": "/echo",
"payload": "echo"
},
{
"source": "provider",
"topic": "/echo",
"payload": "echo"
class ObjSpaceTree
def initialize(object_id)
@root = Node.new(object_id)
expand
end
def expand
depth = 0
begin
nodes_at_depth(depth).each do |node|
// force dom element redraws to work around chrome bugs
$.fn.redraw = function() {
return $(this).each(function() {
var n = document.createTextNode(' ');
$(this).append(n);
setTimeout(function() { n.parentNode.removeChild(n); }, 0);
});
}