-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests #471
Comments
There are no test packages or test helpers nor any interfaces bundled in this repository. Back in 2019 #387 was opened which was aiming to implement interfaces for all public methods but it never got merged. Depending on your needs you could use that as an inspiration. If you have trouble using You could create your own interfaces with the methods you use from the library and attach where needed instead of any A third alternative is to look into existing wrappers for this library. amqp-rpc (not only for RPC even though it's name) is a complete wrapper around this library which has methods to be used both as a receiving server or a calling client. The wrapper uses a function which is invoked before every message is sent that can be overridden for unit tests. A fourth alternative would be to actually use a real server in your tests. Depending on what your needs are it might be the best way to do testing. You could use docker for local testing and development and rabbitmq-action for GitHub actions or rabbitmq service in Travis. 1 Example type Publisher interface {
Publish(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error
}
func somethingThatWillPublish(p Publisher) {
// ...
p.Publish("", "", false, false, someMessage)
// ...
} In production conn, _ := amqp.Dial("amqp://guest:guest@localhost:5672/")
ch, _ := conn.Channel()
somethingThatWillPublish(ch) In your unittests type mockPublisherNoError struct {}
func (_ *mockPublisherNoError) Publish(_, _ string, _, _ bool, _ amqp.Publishing) error {
return nil
}
mp := &mockPublisherNoError{}
somethingThatWillPublish(mp) |
I try to testing my code (used this lib) and I have some problem.
How to create some mock server for amqp?
My tries:
How to use this lib in unit tests?
The text was updated successfully, but these errors were encountered: