karafka-testing 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d62320a4a1e6b7caeb25308b9ea810d7948a887cad788b5779e31320a522f52d
4
+ data.tar.gz: d68f15b96e0ba30d9ebbefce725cf5069842c2f05d6f21c2e22eafa7cea13125
5
+ SHA512:
6
+ metadata.gz: 3a7bfbbac01df4b3839b959c6af809fd3f3f563893b991d4c62fbf4205c9bbf1a314c8d209536e95b33d5bf1031dce41b70d4f1da33bc19172f8736d36a0b063
7
+ data.tar.gz: e755c0bbdad3694d2cff2234db2710e16c1ea98785c563cbb3aaf9b219613366ccbd5636c5ecbc11fdf25b96b708729eb97510994895d28722335b4e35a07daf
@@ -0,0 +1,2 @@
1
+ #�r�R
2
+ b!��0�u���.�7I��5�# h밵�~Zp�Q{b*t+ � �ycV���q-�}����yń$ө ����V x����� [v�?����1]��k��q�
Binary file
@@ -0,0 +1,3 @@
1
+ repository_id: '4e6326c4-68ac-450e-bf4b-7c9de95f1eee'
2
+ api_key: <%= ENV['CODITSU_API_KEY'] %>
3
+ api_secret: <%= ENV['CODITSU_API_SECRET'] %>
@@ -0,0 +1 @@
1
+ open_collective: karafka
@@ -0,0 +1,18 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ schedule:
6
+ - cron: '0 1 * * *'
7
+
8
+ jobs:
9
+ coditsu:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ with:
16
+ fetch-depth: 0
17
+ - name: Run Coditsu
18
+ run: \curl -sSL https://api.coditsu.io/run/ci | bash
@@ -0,0 +1,51 @@
1
+ # Created by .ignore support plugin (hsz.mobi)
2
+ .idea
3
+
4
+ ### SublimeText template
5
+ # cache files for sublime text
6
+ *.tmlanguage.cache
7
+ *.tmPreferences.cache
8
+ *.stTheme.cache
9
+
10
+ # workspace files are user-specific
11
+ *.sublime-workspace
12
+
13
+ # project files should be checked into the repository, unless a significant
14
+ # proportion of contributors will probably not be using SublimeText
15
+ # *.sublime-project
16
+
17
+ # sftp configuration file
18
+ sftp-config.json
19
+
20
+
21
+ ### Ruby template
22
+ *.gem
23
+ *.rbc
24
+ /.config
25
+ /coverage/
26
+ /InstalledFiles
27
+ /pkg/
28
+ /spec/reports/
29
+ /test/tmp/
30
+ /test/version_tmp/
31
+ /tmp/
32
+
33
+ ## Specific to RubyMotion:
34
+ .dat*
35
+ .repl_history
36
+ build/
37
+
38
+ ## Documentation cache and generated files:
39
+ /.yardoc/
40
+ /_yardoc/
41
+ /doc/
42
+ /rdoc/
43
+
44
+ ## Environment normalisation:
45
+ /.bundle/
46
+ /vendor/bundle
47
+ /app/lib/bundler/man/
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+ .coditsu/local.yml
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1 @@
1
+ karafka-testing
@@ -0,0 +1 @@
1
+ 2.7.1
@@ -0,0 +1,14 @@
1
+ # Karafka Test gem changelog
2
+
3
+ ## 1.3.1 (2020-04-24)
4
+ - change license to LGPL-3.0
5
+ - Ruby 2.6.5 support
6
+ - Ruby 2.7.1 support
7
+ - JRuby support
8
+ - Change license to LGPL-3.0
9
+
10
+ ## 1.3.0 (2019-09-09)
11
+ - Dynamic `App` name (#2)
12
+
13
+ ## 1.3.0.rc1 (2019-07-31)
14
+ - Support for Karafka 1.3
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,104 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ karafka-testing (1.3.1)
5
+ karafka (~> 1.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ concurrent-ruby (1.1.6)
11
+ delivery_boy (1.0.1)
12
+ king_konf (~> 0.3)
13
+ ruby-kafka (~> 1.0)
14
+ digest-crc (0.5.1)
15
+ dry-configurable (0.11.5)
16
+ concurrent-ruby (~> 1.0)
17
+ dry-core (~> 0.4, >= 0.4.7)
18
+ dry-equalizer (~> 0.2)
19
+ dry-container (0.7.2)
20
+ concurrent-ruby (~> 1.0)
21
+ dry-configurable (~> 0.1, >= 0.1.3)
22
+ dry-core (0.4.9)
23
+ concurrent-ruby (~> 1.0)
24
+ dry-equalizer (0.3.0)
25
+ dry-events (0.2.0)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-core (~> 0.4)
28
+ dry-equalizer (~> 0.2)
29
+ dry-inflector (0.2.0)
30
+ dry-initializer (3.0.3)
31
+ dry-logic (1.0.6)
32
+ concurrent-ruby (~> 1.0)
33
+ dry-core (~> 0.2)
34
+ dry-equalizer (~> 0.2)
35
+ dry-monitor (0.3.2)
36
+ dry-configurable (~> 0.5)
37
+ dry-core (~> 0.4)
38
+ dry-equalizer (~> 0.2)
39
+ dry-events (~> 0.2)
40
+ dry-schema (1.5.0)
41
+ concurrent-ruby (~> 1.0)
42
+ dry-configurable (~> 0.8, >= 0.8.3)
43
+ dry-core (~> 0.4)
44
+ dry-equalizer (~> 0.2)
45
+ dry-initializer (~> 3.0)
46
+ dry-logic (~> 1.0)
47
+ dry-types (~> 1.4)
48
+ dry-types (1.4.0)
49
+ concurrent-ruby (~> 1.0)
50
+ dry-container (~> 0.3)
51
+ dry-core (~> 0.4, >= 0.4.4)
52
+ dry-equalizer (~> 0.3)
53
+ dry-inflector (~> 0.1, >= 0.1.2)
54
+ dry-logic (~> 1.0, >= 1.0.2)
55
+ dry-validation (1.5.0)
56
+ concurrent-ruby (~> 1.0)
57
+ dry-container (~> 0.7, >= 0.7.1)
58
+ dry-core (~> 0.4)
59
+ dry-equalizer (~> 0.2)
60
+ dry-initializer (~> 3.0)
61
+ dry-schema (~> 1.5)
62
+ envlogic (1.1.2)
63
+ dry-inflector (~> 0.1)
64
+ io-console (0.5.6)
65
+ irb (1.2.3)
66
+ reline (>= 0.0.1)
67
+ karafka (1.3.5)
68
+ dry-configurable (~> 0.8)
69
+ dry-inflector (~> 0.1)
70
+ dry-monitor (~> 0.3)
71
+ dry-validation (~> 1.2)
72
+ envlogic (~> 1.1)
73
+ irb (~> 1.0)
74
+ multi_json (>= 1.12)
75
+ rake (>= 11.3)
76
+ ruby-kafka (>= 0.7.8)
77
+ thor (>= 0.20)
78
+ waterdrop (~> 1.3.0)
79
+ zeitwerk (~> 2.1)
80
+ king_konf (0.3.7)
81
+ multi_json (1.14.1)
82
+ rake (13.0.1)
83
+ reline (0.1.3)
84
+ io-console (~> 0.5)
85
+ ruby-kafka (1.0.0)
86
+ digest-crc
87
+ thor (1.0.1)
88
+ waterdrop (1.3.4)
89
+ delivery_boy (>= 0.2, < 2.x)
90
+ dry-configurable (~> 0.8)
91
+ dry-monitor (~> 0.3)
92
+ dry-validation (~> 1.2)
93
+ ruby-kafka (>= 0.7.8)
94
+ zeitwerk (~> 2.1)
95
+ zeitwerk (2.3.0)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ karafka-testing!
102
+
103
+ BUNDLED WITH
104
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,78 @@
1
+ # Karafka Testing library
2
+
3
+ [![Build Status](https://github.com/karafka/testing/workflows/ci/badge.svg)](https://github.com/karafka/testing/actions?query=workflow%3Aci)
4
+ [![Join the chat at https://gitter.im/karafka/karafka](https://badges.gitter.im/karafka/karafka.svg)](https://gitter.im/karafka/karafka?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
+
6
+ Karafka-Testing is a library that provides rspec helpers, to make testing of Karafka consumers much easier.
7
+
8
+ ## Installation
9
+
10
+ Add this gem to your Gemfile in the `test` group:
11
+ ```ruby
12
+ group :test do
13
+ gem 'karafka-testing'
14
+ gem 'rspec'
15
+ end
16
+ ```
17
+
18
+ and then in your `spec_helper.rb` file:
19
+
20
+ ```ruby
21
+ require 'karafka/testing/rspec/helpers'
22
+
23
+ RSpec.configure do |config|
24
+ config.include Karafka::Testing::RSpec::Helpers
25
+ end
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Once included into your RSpec setup, this library will provide you two methods that you can use with your specs:
31
+
32
+ - `#karafka_consumer_for` - this method will create a consumer instance for the desired topic. It **needs** to be set as the spec subject.
33
+ - `#publish_for_karafka` - this method will "send" message to the consumer instance.
34
+
35
+
36
+ **Note:** Messages sent using the `#publish_for_karafka` method won't be sent to Kafka. They will be "virtually" delegated to the created consumer instance so your specs can run without Kafka setup.
37
+
38
+ ```ruby
39
+ RSpec.describe InlineBatchConsumer do
40
+ # This will create a consumer instance with all the settings defined for the given topic
41
+ subject(:consumer) { karafka_consumer_for(:inline_batch_data) }
42
+
43
+ let(:nr1_value) { rand }
44
+ let(:nr2_value) { rand }
45
+ let(:sum) { nr1_value + nr2_value }
46
+
47
+ before do
48
+ # Sends first message to Karafka consumer
49
+ publish_for_karafka({ 'number' => nr1_value }.to_json)
50
+ # Sends second message to Karafka consumer
51
+ publish_for_karafka({ 'number' => nr2_value }.to_json)
52
+ allow(Karafka.logger).to receive(:info)
53
+ end
54
+
55
+ it 'expects to log a proper message' do
56
+ expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
57
+ consumer.consume
58
+ end
59
+ end
60
+ ```
61
+
62
+ ## References
63
+
64
+ * [Karafka framework](https://github.com/karafka/karafka)
65
+ * [Karafka Testing Actions CI](https://github.com/karafka/testing/actions?query=workflow%3Aci)
66
+ * [Karafka Testing Coditsu](https://app.coditsu.io/karafka/repositories/testing)
67
+
68
+ ## Note on contributions
69
+
70
+ First, thank you for considering contributing to Karafka Testing! It's people like you that make the open source community such a great community!
71
+
72
+ Each pull request must pass all the RSpec specs and meet our quality requirements.
73
+
74
+ To check if everything is as it should be, we use [Coditsu](https://coditsu.io) that combines multiple linters and code analyzers for both code and documentation. Once you're done with your changes, submit a pull request.
75
+
76
+ Coditsu will automatically check your work against our quality standards. You can find your commit check results on the [builds page](https://app.coditsu.io/karafka/repositories/test/builds/commit_builds) of the Karafka Testing repository.
77
+
78
+ [![coditsu](https://coditsu.io/assets/quality_bar.svg)](https://app.coditsu.io/karafka/repositories/testing/builds/commit_builds)
@@ -0,0 +1,25 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
3
+ ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMTkwNzMwMTQ1NDU0WhcNMjAwNzI5MTQ1
4
+ NDU0WjAjMSEwHwYDVQQDDBhtYWNpZWovREM9bWVuc2ZlbGQvREM9cGwwggGiMA0G
5
+ CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC9fCwtaHZG2SyyNXiH8r0QbJQx/xxl
6
+ dkvwWz9QGJO+O8rEx20FB1Ab+MVkfOscwIv5jWpmk1U9whzDPl1uFtIbgu+sk+Zb
7
+ uQlZyK/DPN6c+/BbBL+RryTBRyvkPLoCVwm7uxc/JZ1n4AI6eF4cCZ2ieZ9QgQbU
8
+ MQs2QPqs9hT50Ez/40GnOdadVfiDDGz+NME2C4ms0BriXwZ1tcRTfJIHe2xjIbbb
9
+ y5qRGfsLKcgMzvLQR24olixyX1MR0s4+Wveq3QL/gBhL4veUcv+UABJA8IJR0kyB
10
+ seHHutusiwZ1v3SjjjW1xLLrc2ARV0mgCb0WaK2T4iA3oFTGLh6Ydz8LNl31KQFv
11
+ 94nRd8IhmJxrhQ6dQ/WT9IXoa5S9lfT5lPJeINemH4/6QPABzf9W2IZlCdI9wCdB
12
+ TBaw57MKneGAYZiKjw6OALSy2ltQUCl3RqFl3VP7n8uFy1U987Q5VIIQ3O1UUsQD
13
+ Oe/h+r7GUU4RSPKgPlrwvW9bD/UQ+zF51v8CAwEAAaN3MHUwCQYDVR0TBAIwADAL
14
+ BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFJNIBHdfEUD7TqHqIer2YhWaWhwcMB0GA1Ud
15
+ EQQWMBSBEm1hY2llakBtZW5zZmVsZC5wbDAdBgNVHRIEFjAUgRJtYWNpZWpAbWVu
16
+ c2ZlbGQucGwwDQYJKoZIhvcNAQELBQADggGBAKA4eqko6BTNhlysip6rfBkVTGri
17
+ ZXsL+kRb2hLvsQJS/kLyM21oMlu+LN0aPj3qEFR8mE/YeDD8rLAfruBRTltPNbR7
18
+ xA5eE1gkxY5LfExUtK3b2wPqfmo7mZgfcsMwfYg/tUXw1WpBCnrhAJodpGH6SXmp
19
+ A40qFUZst0vjiOoO+aTblIHPmMJXoZ3K42dTlNKlEiDKUWMRKSgpjjYGEYalFNWI
20
+ hHfCz2r8L2t+dYdMZg1JGbEkq4ADGsAA8ioZIpJd7V4hI17u5TCdi7X5wh/0gN0E
21
+ CgP+nLox3D+l2q0QuQEkayr+auFYkzTCkF+BmEk1D0Ru4mcf3F4CJvEmW4Pzbjqt
22
+ i1tsCWPtJ4E/UUKnKaWKqGbjrjHJ0MuShYzHkodox5IOiCXIQg+1+YSzfXUV6WEK
23
+ KJG/fhg1JV5vVDdVy6x+tv5SQ5ctU0feCsVfESi3rE3zRd+nvzE9HcZ5aXeL1UtJ
24
+ nT5Xrioegu2w1jPyVEgyZgTZC5rvD0nNS5sFNQ==
25
+ -----END CERTIFICATE-----
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'karafka/testing/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'karafka-testing'
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.version = Karafka::Testing::VERSION
12
+ spec.authors = ['Maciej Mensfeld']
13
+ spec.email = %w[maciej@mensfeld.pl]
14
+ spec.summary = 'Library which provides helpers for easier Karafka consumers tests'
15
+ spec.description = 'Library which provides helpers for easier Karafka consumers tests'
16
+ spec.homepage = 'https://github.com/karafka/testing'
17
+ spec.license = 'LGPL-3.0'
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = %w[lib]
21
+ spec.cert_chain = %w[certs/mensfeld.pem]
22
+
23
+ spec.required_ruby_version = '>= 2.5.0'
24
+
25
+ if $PROGRAM_NAME.end_with?('gem')
26
+ spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
27
+ end
28
+
29
+ spec.add_dependency 'karafka', '~> 1.3.0'
30
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'karafka/testing'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Main Karafka module
4
+ module Karafka
5
+ # Testing lib module
6
+ module Testing
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Main module to encapsulate logic
4
+ module Karafka
5
+ module Testing
6
+ # Errors that can be raised by this lib
7
+ module Errors
8
+ # Base error for all the internal errors
9
+ BaseError = Class.new(StandardError)
10
+ # Raised when we want to build a consumer for a topic that does not exist
11
+ TopicNotFoundError = Class.new(BaseError)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'karafka/testing/errors'
4
+
5
+ module Karafka
6
+ module Testing
7
+ # All the things related to extra functionalities needed to easier spec out
8
+ # Karafka things using RSpec
9
+ module RSpec
10
+ # RSpec helpers module that needs to be included
11
+ module Helpers
12
+ class << self
13
+ # Adds all the needed extra functionalities to the rspec group
14
+ # @param base [Class] RSpec example group we want to extend
15
+ def included(base)
16
+ # This is an internal buffer for keeping "to be sent" messages before
17
+ # we run the consume
18
+ base.let(:_karafka_raw_data) { [] }
19
+ # Clear the messages buffer after each spec, so nothing will leak
20
+ # in between them
21
+ base.after { _karafka_raw_data.clear }
22
+ end
23
+ end
24
+
25
+ # Creates a consumer instance for given topic
26
+ # @param requested_topic [String, Symbol] name of the topic for which we want to
27
+ # create a consumer instance
28
+ # @return [Object] described_class instance
29
+ # @raise [Karafka::Testing::Errors::TopicNotFoundError] raised when we're unable to find
30
+ # topic that was requested
31
+ #
32
+ # @example Creates a MyConsumer consumer instance with settings for `my_requested_topic`
33
+ # RSpec.describe MyConsumer do
34
+ # subject(:consumer) { karafka_consumer_for(:my_requested_topic) }
35
+ # end
36
+ def karafka_consumer_for(requested_topic)
37
+ selected_topic = nil
38
+
39
+ # @note Remove in 2.0. This won't work without the global state
40
+ ::Karafka::App.consumer_groups.each do |consumer_group|
41
+ consumer_group.topics.each do |topic|
42
+ selected_topic = topic if topic.name == requested_topic.to_s
43
+ end
44
+ end
45
+
46
+ raise Karafka::Testing::Errors::TopicNotFoundError, requested_topic unless selected_topic
47
+
48
+ described_class.new(selected_topic)
49
+ end
50
+
51
+ # Adds a new Karafka params instance with given payload and options into an internal
52
+ # buffer that will be used to simulate messages delivery to the consumer
53
+ #
54
+ # @param payload [String] anything you want to send
55
+ # @param opts [Hash] additional options with which you want to overwrite the
56
+ # message defaults (key, offset, etc)
57
+ #
58
+ # @example Send a json message to consumer
59
+ # before do
60
+ # publish_for_karafka({ 'hello' => 'world' }.to_json)
61
+ # end
62
+ #
63
+ # @example Send a json message to consumer and simulate, that it is partition 6
64
+ # before do
65
+ # publish_for_karafka({ 'hello' => 'world' }.to_json, 'partition' => 6)
66
+ # end
67
+ def publish_for_karafka(payload, opts = {})
68
+ _karafka_raw_data << Karafka::Params::Params
69
+ .new
70
+ .merge!(message_defaults)
71
+ .merge!('payload' => payload)
72
+ .merge!(opts)
73
+
74
+ subject.params_batch = Karafka::Params::ParamsBatch
75
+ .new(_karafka_raw_data)
76
+ end
77
+
78
+ private
79
+
80
+ # @return [Hash] message default options
81
+ def message_defaults
82
+ {
83
+ 'deserializer' => subject.topic.deserializer,
84
+ 'create_time' => Time.now,
85
+ 'headers' => {},
86
+ 'is_control_record' => false,
87
+ 'key' => nil,
88
+ 'offset' => 0,
89
+ 'partition' => 0,
90
+ 'receive_time' => Time.now,
91
+ 'topic' => subject.topic.name
92
+ }
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Main module to encapsulate logic
4
+ module Karafka
5
+ module Testing
6
+ # Current version of gem. It should match Karafka framework version
7
+ VERSION = '1.3.1'
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: karafka-testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Mensfeld
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
14
+ ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMTkwNzMwMTQ1NDU0WhcNMjAwNzI5MTQ1
15
+ NDU0WjAjMSEwHwYDVQQDDBhtYWNpZWovREM9bWVuc2ZlbGQvREM9cGwwggGiMA0G
16
+ CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC9fCwtaHZG2SyyNXiH8r0QbJQx/xxl
17
+ dkvwWz9QGJO+O8rEx20FB1Ab+MVkfOscwIv5jWpmk1U9whzDPl1uFtIbgu+sk+Zb
18
+ uQlZyK/DPN6c+/BbBL+RryTBRyvkPLoCVwm7uxc/JZ1n4AI6eF4cCZ2ieZ9QgQbU
19
+ MQs2QPqs9hT50Ez/40GnOdadVfiDDGz+NME2C4ms0BriXwZ1tcRTfJIHe2xjIbbb
20
+ y5qRGfsLKcgMzvLQR24olixyX1MR0s4+Wveq3QL/gBhL4veUcv+UABJA8IJR0kyB
21
+ seHHutusiwZ1v3SjjjW1xLLrc2ARV0mgCb0WaK2T4iA3oFTGLh6Ydz8LNl31KQFv
22
+ 94nRd8IhmJxrhQ6dQ/WT9IXoa5S9lfT5lPJeINemH4/6QPABzf9W2IZlCdI9wCdB
23
+ TBaw57MKneGAYZiKjw6OALSy2ltQUCl3RqFl3VP7n8uFy1U987Q5VIIQ3O1UUsQD
24
+ Oe/h+r7GUU4RSPKgPlrwvW9bD/UQ+zF51v8CAwEAAaN3MHUwCQYDVR0TBAIwADAL
25
+ BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFJNIBHdfEUD7TqHqIer2YhWaWhwcMB0GA1Ud
26
+ EQQWMBSBEm1hY2llakBtZW5zZmVsZC5wbDAdBgNVHRIEFjAUgRJtYWNpZWpAbWVu
27
+ c2ZlbGQucGwwDQYJKoZIhvcNAQELBQADggGBAKA4eqko6BTNhlysip6rfBkVTGri
28
+ ZXsL+kRb2hLvsQJS/kLyM21oMlu+LN0aPj3qEFR8mE/YeDD8rLAfruBRTltPNbR7
29
+ xA5eE1gkxY5LfExUtK3b2wPqfmo7mZgfcsMwfYg/tUXw1WpBCnrhAJodpGH6SXmp
30
+ A40qFUZst0vjiOoO+aTblIHPmMJXoZ3K42dTlNKlEiDKUWMRKSgpjjYGEYalFNWI
31
+ hHfCz2r8L2t+dYdMZg1JGbEkq4ADGsAA8ioZIpJd7V4hI17u5TCdi7X5wh/0gN0E
32
+ CgP+nLox3D+l2q0QuQEkayr+auFYkzTCkF+BmEk1D0Ru4mcf3F4CJvEmW4Pzbjqt
33
+ i1tsCWPtJ4E/UUKnKaWKqGbjrjHJ0MuShYzHkodox5IOiCXIQg+1+YSzfXUV6WEK
34
+ KJG/fhg1JV5vVDdVy6x+tv5SQ5ctU0feCsVfESi3rE3zRd+nvzE9HcZ5aXeL1UtJ
35
+ nT5Xrioegu2w1jPyVEgyZgTZC5rvD0nNS5sFNQ==
36
+ -----END CERTIFICATE-----
37
+ date: 2020-04-24 00:00:00.000000000 Z
38
+ dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: karafka
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.0
53
+ description: Library which provides helpers for easier Karafka consumers tests
54
+ email:
55
+ - maciej@mensfeld.pl
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - ".coditsu/ci.yml"
61
+ - ".github/FUNDING.yml"
62
+ - ".github/workflows/ci.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".ruby-version"
67
+ - CHANGELOG.md
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE
71
+ - README.md
72
+ - certs/mensfeld.pem
73
+ - karafka-testing.gemspec
74
+ - lib/karafka-testing.rb
75
+ - lib/karafka/testing.rb
76
+ - lib/karafka/testing/errors.rb
77
+ - lib/karafka/testing/rspec/helpers.rb
78
+ - lib/karafka/testing/version.rb
79
+ homepage: https://github.com/karafka/testing
80
+ licenses:
81
+ - LGPL-3.0
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.5.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.1.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Library which provides helpers for easier Karafka consumers tests
102
+ test_files: []
Binary file