karafka-testing 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7a7e11e7f5ba273fc7875d3c20bd2b1457d46f315f168e933f1f48f82f6bbf6
4
- data.tar.gz: 0ac2a1804d0b7e94cfd409763edd8ced61dd64fdde2219d9d42a375f9a21542a
3
+ metadata.gz: 513e1bb6f2a9ac5806fc7df36f788f4ba1b1f72286110e0584ad882d347453fe
4
+ data.tar.gz: a758a804787420eea61375763bcad90a6c2033426d46f8b07707fc5c22d9de72
5
5
  SHA512:
6
- metadata.gz: 38d9372fcf299860d91efe18061ed219583a95fb1955a4817536a9fe4ae5ac6e9f86fc4e92c35c02a256cf9b9a1162f0a2cd54c17d6dd48b503f9a36c1d2be6c
7
- data.tar.gz: fa0f0e8395e9fc00b155074a5e0059ad8dc4aecf0f9e93b0edaf6806574a873e17e183ad8bbede526237e3dcd321b378664252755d05d82204329c3351361861
6
+ metadata.gz: e313af611899b8a3b47791d63694b24612bd97b27dde6262b929a7af315b64c0c2a1e0fd0b22fe25838d41b3c592c302b610e67031b44b27f08ee2daf78a4705
7
+ data.tar.gz: 18d88784906a4d19a33dab5ceca6236c1720d488c58b56e324464eb5730096c5f3bcfcfa3b8481fe4db974c10a2d294d3c91a50b9d7c030e28a0314531c1798c
checksums.yaml.gz.sig CHANGED
Binary file
@@ -61,7 +61,7 @@ jobs:
61
61
  strategy:
62
62
  fail-fast: false
63
63
  steps:
64
- - uses: actions/checkout@v2
64
+ - uses: actions/checkout@v3
65
65
  with:
66
66
  fetch-depth: 0
67
67
  - name: Run Coditsu
data/2.0-Upgrade.md CHANGED
@@ -7,7 +7,7 @@ Karafka-Testing 2.0 some breaking changes in the way consumer builder and messag
7
7
  Please upgrade your application to `Karafka 2.0` first.
8
8
 
9
9
  - Replace `#karafka_consumer_for` in your specs with `#karafka.consumer_for`
10
- - Replace `#publish_for_karafka` in your specs with `#karafka.publish`
10
+ - Replace `#publish_for_karafka` in your specs with `#karafka.produce`
11
11
 
12
12
  And that's all!
13
13
 
@@ -24,8 +24,8 @@ RSpec.describe CountersConsumer do
24
24
  let(:sum) { nr1_value + nr2_value }
25
25
 
26
26
  before do
27
- karafka.publish({ 'number' => nr1_value }.to_json)
28
- karafka.publish({ 'number' => nr2_value }.to_json, partition: 2)
27
+ karafka.produce({ 'number' => nr1_value }.to_json)
28
+ karafka.produce({ 'number' => nr2_value }.to_json, partition: 2)
29
29
  allow(Karafka.logger).to receive(:info)
30
30
  end
31
31
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Karafka Test gem changelog
2
2
 
3
+ ## 2.0.5 (2022-10-19)
4
+ - Fix for: Test event production without defining a subject (#102)
5
+
6
+ ## 2.0.4 (2022-10-14)
7
+ - Align changes with Karafka `2.0.13` changes.
8
+
3
9
  ## 2.0.3 (2022-09-30)
4
10
  - Fix direct name reference `consumer` instead of `subject` (#97).
5
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.0.3)
4
+ karafka-testing (2.0.5)
5
5
  karafka (>= 2.0, < 3.0.0)
6
6
 
7
7
  GEM
@@ -9,13 +9,13 @@ GEM
9
9
  specs:
10
10
  concurrent-ruby (1.1.10)
11
11
  ffi (1.15.5)
12
- karafka (2.0.11)
12
+ karafka (2.0.14)
13
13
  karafka-core (>= 2.0.2, < 3.0.0)
14
14
  rdkafka (>= 0.12)
15
15
  thor (>= 0.20)
16
16
  waterdrop (>= 2.4.1, < 3.0.0)
17
17
  zeitwerk (~> 2.3)
18
- karafka-core (2.0.2)
18
+ karafka-core (2.0.3)
19
19
  concurrent-ruby (>= 1.1)
20
20
  mini_portile2 (2.8.0)
21
21
  rake (13.0.6)
@@ -28,13 +28,14 @@ GEM
28
28
  karafka-core (>= 2.0.2, < 3.0.0)
29
29
  rdkafka (>= 0.10)
30
30
  zeitwerk (~> 2.3)
31
- zeitwerk (2.6.0)
31
+ zeitwerk (2.6.1)
32
32
 
33
33
  PLATFORMS
34
+ arm64-darwin
34
35
  x86_64-linux
35
36
 
36
37
  DEPENDENCIES
37
38
  karafka-testing!
38
39
 
39
40
  BUNDLED WITH
40
- 2.3.22
41
+ 2.3.24
data/README.md CHANGED
@@ -6,114 +6,9 @@
6
6
 
7
7
  Karafka-Testing is a library that provides RSpec helpers, to make testing of Karafka consumers and producer much easier.
8
8
 
9
- ## Installation
9
+ ## Installation and usage
10
10
 
11
- Add this gem to your Gemfile in the `test` group:
12
- ```ruby
13
- group :test do
14
- gem 'karafka-testing'
15
- gem 'rspec'
16
- end
17
- ```
18
-
19
- and then in your `spec_helper.rb` file:
20
-
21
- ```ruby
22
- require 'karafka/testing/rspec/helpers'
23
-
24
- RSpec.configure do |config|
25
- config.include Karafka::Testing::RSpec::Helpers
26
- end
27
- ```
28
-
29
- ## Usage
30
-
31
- Once included in your RSpec setup, this library will provide you with a special `#karafka` object that contains three methods that you can use within your specs:
32
-
33
- - `#consumer_for` - creates a consumer instance for the desired topic. It **needs** to be set as the spec subject.
34
- - `#produce` - "sends" message to the consumer instance.
35
- - `#produced_messages` - contains all the messages "sent" to Kafka during spec execution.
36
-
37
- **Note:** Messages sent using the `#produce` method and directly from `Karafka.producer` won't be sent to Kafka. They will be buffered and accessible in a per-spec buffer in case you want to test messages production.
38
-
39
- Messages that target the topic built using the `karafka#consumer_for` method will additionally be delivered to the consumer you want to test.
40
-
41
- ### Testing messages consumption (consumers)
42
-
43
- ```ruby
44
- RSpec.describe InlineBatchConsumer do
45
- # This will create a consumer instance with all the settings defined for the given topic
46
- subject(:consumer) { karafka.consumer_for('inline_batch_data') }
47
-
48
- let(:nr1_value) { rand }
49
- let(:nr2_value) { rand }
50
- let(:sum) { nr1_value + nr2_value }
51
-
52
- before do
53
- # Sends first message to Karafka consumer
54
- karafka.produce({ 'number' => nr1_value }.to_json)
55
-
56
- # Sends second message to Karafka consumer
57
- karafka.produce({ 'number' => nr2_value }.to_json, partition: 2)
58
-
59
- allow(Karafka.logger).to receive(:info)
60
- end
61
-
62
- it 'expects to log a proper message' do
63
- expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
64
- consumer.consume
65
- end
66
- end
67
- ```
68
-
69
- If your consumers use `producer` to dispatch messages, you can check its operations as well:
70
-
71
- ```ruby
72
- RSpec.describe InlineBatchConsumer do
73
- subject(:consumer) { karafka.consumer_for(:inline_batch_data) }
74
-
75
- before { karafka.produce({ 'number' => 1 }.to_json) }
76
-
77
- it 'expects to dispatch async message to messages topic with value bigger by 1' do
78
- consumer.consume
79
-
80
- expect(karafka.produced_messages.last.payload).to eq({ number: 2 }.to_json)
81
- end
82
- end
83
- ```
84
-
85
- ### Testing messages production (producer)
86
-
87
- When running RSpec, Karafka will not dispatch messages to Kafka using `Karafka.producer` but will buffer them internally.
88
-
89
- This means you can check your application flow, making sure your logic acts as expected:
90
-
91
- ```ruby
92
- # Example class in which there is a message production
93
- class UsersBuilder
94
- def create(user_details)
95
- user = ::User.create!(user_details)
96
-
97
- Karafka.producer.produce_sync(
98
- topic: 'users_changes',
99
- payload: { user_id: user.id, type: 'user.created' },
100
- key: user.id.to_s
101
- )
102
-
103
- user
104
- end
105
- end
106
-
107
- RSpec.describe InlineBatchConsumer do
108
- let(:created_user) { UsersBuilder.new.create(user_details) }
109
-
110
- before { created_user }
111
-
112
- it { expect(karafka.produced_messages.size).to eq(1) }
113
- it { expect(karafka.produced_messages.first[:topic]).to eq('user.created') }
114
- it { expect(karafka.produced_messages.first[:key]).to eq(created_user.id.to_s) }
115
- end
116
- ```
11
+ `karafka-testing` docs are part of Karafka framework docs. You can find the testing section [here](https://karafka.io/docs/Testing/).
117
12
 
118
13
  ## Note on contributions
119
14
 
@@ -85,6 +85,10 @@ module Karafka
85
85
  # karafka.produce({ 'hello' => 'world' }.to_json, 'partition' => 6)
86
86
  # end
87
87
  def _karafka_add_message_to_consumer_if_needed(message)
88
+ # We're interested in adding message to subject only when it is a consumer
89
+ # Users may want to test other things (models producing messages for example) and in
90
+ # their case subject will not be a consumer
91
+ return unless subject.is_a?(Karafka::BaseConsumer)
88
92
  # We target to the consumer only messages that were produced to it, since specs may also
89
93
  # produce other messages targeting other topics
90
94
  return unless message[:topic] == subject.topic.name
@@ -163,6 +167,7 @@ module Karafka
163
167
  consumer.producer = Karafka::App.producer
164
168
  consumer.client = _karafka_consumer_client
165
169
  consumer.coordinator = coordinators.find_or_create(topic.name, 0)
170
+ consumer.coordinator.seek_offset = 0
166
171
  consumer
167
172
  end
168
173
  end
@@ -4,6 +4,6 @@
4
4
  module Karafka
5
5
  module Testing
6
6
  # Current version of gem. It should match Karafka framework version
7
- VERSION = '2.0.3'
7
+ VERSION = '2.0.5'
8
8
  end
9
9
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka-testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2022-09-30 00:00:00.000000000 Z
38
+ date: 2022-10-19 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka
metadata.gz.sig CHANGED
Binary file