wabbit icon indicating copy to clipboard operation
wabbit copied to clipboard

Examples for usage with streadway/amqp

Open andysnowden opened this issue 6 years ago • 1 comments

It's mentioned in the readme that this should be possible but I'm wonder if we could get some examples showing this.

For example I'd like to mock the server/connection/channel then pass that down to my function which uses streadway/amqp from that point on.

andysnowden avatar Aug 29 '19 20:08 andysnowden

You inject a wabbit.Conn to your function.

In your test, you can attack a fake server or a real server like this:

	url := "amqp://localhost:32771"

	isRealServer := true
	var err error
	var conn wabbit.Conn
	if isRealServer {
		conn, err = amqp.Dial(url)
	} else {
		fakeServer := server.NewServer(url)
		fakeServer.Start()
		conn, err = amqptest.Dial(url)
	}

	assert.NoError(t, err)

I for e.g pass the conn to my rabbitMQMessageBroker constructor, it will setup the exchanges, setup the queue etc.

gonzaloserrano avatar Oct 02 '19 10:10 gonzaloserrano