-
Notifications
You must be signed in to change notification settings - Fork 22
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
GUILD-619: Test helpers don't automatically reset to test config #120
Changes from 8 commits
9d8b8e9
0d7c5a1
a8e87dc
9423cb0
d7c8da6
a1c1926
60787fc
eeb2243
3ff1d7e
8040edb
bcf8bef
1fc082c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ Built on Phobos and hence Ruby-Kafka. | |
* [Running Consumers](#running-consumers) | ||
* [Metrics](#metrics) | ||
* [Testing](#testing) | ||
* [Default Deimos config for testing](#default-deimos-config-for-testing) | ||
* [Integration Test Helpers](#integration-test-helpers) | ||
* [Utilities](#utilities) | ||
* [Contributing](#contributing) | ||
|
@@ -935,6 +936,18 @@ expect(message).to eq({ | |
topic: 'my-topic', | ||
key: 'my-id' | ||
}) | ||
|
||
## Configuring Deimos to test settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this shouldn't be in the code block with everything else because it likely won't be in the test itself. Also, the previous examples in this block will only work if the test producers are being used, so we should call that out and put this explanation before that block. You can give an example of a # spec_helper.rb
RSpec.before(:each) do
configure_deimos
end Actually, now that I write this, it would be even better if we can allow this method to take a block and reset the config back to what it was. Then you could use it like this: RSpec.around(:each) do |ex|
configure_deimos({...}) do
ex.run
end ...and we would be able to ensure that config didn't leak past examples, which is something that's bitten me multiple times. You can deep-dup the config and restore it after the block is run. |
||
|
||
# You can reset Deimos to default test config by calling this method. | ||
configure_deimos | ||
|
||
# The same method can be used to override settings while still using | ||
# deafults for other fields. | ||
configure_deimos(consumers: { reraise_errors: false }, | ||
producers: { topic_prefix: nil }, | ||
db_producer: { compact_topics: %w(my-topic my-topic2) }, | ||
logger: Rails.logger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I like this a lot! I think there might be some other changes to the README that are necessary - e.g. we should be calling out things like the test producer and how to interact with it rather than assuming that when you include TestHelpers you get it for free. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dorner I tried my best to add more info but there might be some that I missed and/or added incorrect information. Please let me know! |
||
``` | ||
|
||
There is also a helper method that will let you test if an existing schema | ||
|
@@ -946,6 +959,28 @@ require 'deimos/test_helpers' | |
# Can pass a file path, a string or a hash into this: | ||
Deimos::TestHelpers.schemas_compatible?(schema1, schema2) | ||
``` | ||
### Default Deimos config for testing | ||
|
||
The test helper class provides the default settings for Deimos config. | ||
```ruby | ||
# The following are the test defaults for Deimos that are set | ||
# by calling `configure_deimos` | ||
DEFAULT_TEST_CONFIG = { | ||
logger: Logger.new(STDOUT), | ||
consumers: { reraise_errors: true }, | ||
kafka: { seed_brokers: ['test_broker'] }, | ||
schema: { backend: Deimos.schema_backend_class.mock_backend }, | ||
producers: { backend: :test } | ||
} | ||
``` | ||
`:test` is the default backend for producers that saves messages | ||
to an in-memory hash. You can access the sent messages by calling | ||
the following function | ||
```ruby | ||
Deimos::Backends::Test.sent_messages | ||
``` | ||
Mock schema backend will perform all the validations but not actually encode any messages. | ||
|
||
|
||
### Integration Test Helpers | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should call out in bold that this is a breaking change.