Code Monkey home page Code Monkey logo

wabbit's Introduction

Wabbit - Go AMQP Mocking Library

GoDoc Go Report Card

Elmer Fudd: Shhh. Be vewy vewy quiet, I'm hunting wabbits

AMQP is a verbose protocol that makes it difficult to implement proper unit-testing on your application. The first goal of this package is provide a sane interface for an AMQP client implementation based on the specification AMQP-0-9-1 (no extension) and then an implementation of this interface using the well established package streadway/amqp (a wrapper).

What are the advantages of this?

Usage

How to use ?

Testing

This package have an AMQP interface and two possible implementations:

In the same way you can use the http package in your software and use the httptest for testing, when using wabbit is recommended to use the wabbit/amqp package on your software and wabbit/amqptest in your tests. Simple test example:

package main

import (
	"testing"
	"github.com/NeowayLabs/wabbit/amqptest"
	"github.com/NeowayLabs/wabbit/amqptest/server"
	"github.com/NeowayLabs/wabbit/amqp"
)


func TestChannelCreation(t *testing.T) {
	mockConn, err := amqptest.Dial("amqp://localhost:5672/%2f") // will fail,

	if err == nil {
		t.Error("This shall fail, because no fake amqp server is running...")
	}

	fakeServer := server.NewServer("amqp://localhost:5672/%2f")
	fakeServer.Start()

	mockConn, err = amqptest.Dial("amqp://localhost:5672/%2f") // now it works =D

	if err != nil {
		t.Error(err)
	}

	//Now you can use mockConn as a real amqp connection.
	channel, err := mockConn.Channel()

    // ...
}

The package amqptest/server implements a mock AMQP server and it can be used to simulate network partitions or broker crashs. To create a new server instance use server.NewServer passing any amqpuri. You can create more than one server, but they need to have different amqpuris. Example below:

    broker1 := server.NewServer("amqp://localhost:5672/%2f")
    broker2 := server.NewServer("amqp://192.168.10.165:5672/%2f")
    broker3 := server.NewServer("amqp://192.168.10.169:5672/%2f")

    broker1.Start()
    broker2.Start()
    broker3.Start()

Calling NewServer with same amqpuri will return the same server instance.

Use broker.Stop() to abruptly stop the amqp server.

There's no fake clustering support yet (maybe never)

It's a very straightforward implementation that need a lot of improvements yet. Take careful when using it.

[]'s

wabbit's People

Contributors

alrs avatar cheshir avatar gabo1208 avatar gonzaloserrano avatar i4ki avatar iliyav avatar lucasgomide avatar manavo avatar matheusvill avatar nnathan avatar paran01d avatar satta avatar vaikas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.