项目作者: NeowayLabs

项目描述 :
Golang AMQP mocking library
高级语言: Go
项目地址: git://github.com/NeowayLabs/wabbit.git
创建时间: 2016-03-20T19:08:30Z
项目社区:https://github.com/NeowayLabs/wabbit

开源协议:BSD 2-Clause "Simplified" License

下载


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:

  1. package main
  2. import (
  3. "testing"
  4. "github.com/NeowayLabs/wabbit/amqptest"
  5. "github.com/NeowayLabs/wabbit/amqptest/server"
  6. "github.com/NeowayLabs/wabbit/amqp"
  7. )
  8. func TestChannelCreation(t *testing.T) {
  9. mockConn, err := amqptest.Dial("amqp://localhost:5672/%2f") // will fail,
  10. if err == nil {
  11. t.Error("This shall fail, because no fake amqp server is running...")
  12. }
  13. fakeServer := server.NewServer("amqp://localhost:5672/%2f")
  14. fakeServer.Start()
  15. mockConn, err = amqptest.Dial("amqp://localhost:5672/%2f") // now it works =D
  16. if err != nil {
  17. t.Error(err)
  18. }
  19. //Now you can use mockConn as a real amqp connection.
  20. channel, err := mockConn.Channel()
  21. // ...
  22. }

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:

  1. broker1 := server.NewServer("amqp://localhost:5672/%2f")
  2. broker2 := server.NewServer("amqp://192.168.10.165:5672/%2f")
  3. broker3 := server.NewServer("amqp://192.168.10.169:5672/%2f")
  4. broker1.Start()
  5. broker2.Start()
  6. 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