Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Examples for usage with streadway/amqp #29

Open
andysnowden opened this issue Aug 29, 2019 · 1 comment
Open

Examples for usage with streadway/amqp #29

andysnowden opened this issue Aug 29, 2019 · 1 comment

Comments

@andysnowden
Copy link

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.

@gonzaloserrano
Copy link
Contributor

gonzaloserrano commented Oct 2, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants