karafka-testing 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.coditsu/ci.yml +3 -0
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +51 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +100 -0
- data/MIT-LICENCE +18 -0
- data/README.md +78 -0
- data/certs/mensfeld.pem +25 -0
- data/karafka-testing.gemspec +28 -0
- data/lib/karafka-testing.rb +3 -0
- data/lib/karafka/testing.rb +8 -0
- data/lib/karafka/testing/errors.rb +14 -0
- data/lib/karafka/testing/rspec/helpers.rb +96 -0
- data/lib/karafka/testing/version.rb +9 -0
- metadata +102 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 334e5c351ee5d866326e51d74fb861d9c475bd7299c147b4c74e79f298920097
|
4
|
+
data.tar.gz: abea94cdd6847f57c1230b71975cb50f23ba581d6a848922d6dfaf36275b5469
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c7ce2edd303729dc75eac1080b77dabac897cbf87b340102e131f68a8b6ec75767a55f4ed89c9631fd20b2ec0fd9a145e39b54b4913fd160b2fef056001f857
|
7
|
+
data.tar.gz: 8e1aaef28450c9a5ed48949016d44211b95fe81e166c06b37cc1aef6942cea64361c48ec9e7336b15536ac459261a86fee4d0edf5a52191eb24bf35872f6b4bb
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/.coditsu/ci.yml
ADDED
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
open_collective: karafka
|
data/.gitignore
ADDED
@@ -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
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
karafka-testing
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
services:
|
2
|
+
- docker
|
3
|
+
|
4
|
+
dist: trusty
|
5
|
+
sudo: false
|
6
|
+
cache: bundler
|
7
|
+
|
8
|
+
git:
|
9
|
+
depth: false
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
include:
|
13
|
+
- stage: coditsu
|
14
|
+
language: ruby
|
15
|
+
before_install:
|
16
|
+
- gem update --system
|
17
|
+
- gem install bundler
|
18
|
+
script: \curl -sSL https://api.coditsu.io/run/ci | bash
|
19
|
+
|
20
|
+
stages:
|
21
|
+
- coditsu
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
karafka-testing (1.3.0.rc1)
|
5
|
+
karafka (~> 1.3.0.rc1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
concurrent-ruby (1.1.5)
|
11
|
+
delivery_boy (0.2.8)
|
12
|
+
king_konf (~> 0.3)
|
13
|
+
ruby-kafka (~> 0.7.8)
|
14
|
+
digest-crc (0.4.1)
|
15
|
+
dry-configurable (0.8.3)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
dry-core (~> 0.4, >= 0.4.7)
|
18
|
+
dry-container (0.7.2)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
21
|
+
dry-core (0.4.8)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
dry-equalizer (0.2.2)
|
24
|
+
dry-events (0.2.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
dry-core (~> 0.4)
|
27
|
+
dry-equalizer (~> 0.2)
|
28
|
+
dry-inflector (0.1.2)
|
29
|
+
dry-initializer (3.0.1)
|
30
|
+
dry-logic (1.0.2)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
dry-core (~> 0.2)
|
33
|
+
dry-equalizer (~> 0.2)
|
34
|
+
dry-monitor (0.3.1)
|
35
|
+
dry-configurable (~> 0.5)
|
36
|
+
dry-core (~> 0.4)
|
37
|
+
dry-equalizer (~> 0.2)
|
38
|
+
dry-events (~> 0.1)
|
39
|
+
dry-schema (1.3.1)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
dry-configurable (~> 0.8, >= 0.8.3)
|
42
|
+
dry-core (~> 0.4)
|
43
|
+
dry-equalizer (~> 0.2)
|
44
|
+
dry-initializer (~> 3.0)
|
45
|
+
dry-logic (~> 1.0)
|
46
|
+
dry-types (~> 1.0)
|
47
|
+
dry-types (1.1.1)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
dry-container (~> 0.3)
|
50
|
+
dry-core (~> 0.4, >= 0.4.4)
|
51
|
+
dry-equalizer (~> 0.2, >= 0.2.2)
|
52
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
53
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
54
|
+
dry-validation (1.2.1)
|
55
|
+
concurrent-ruby (~> 1.0)
|
56
|
+
dry-container (~> 0.7, >= 0.7.1)
|
57
|
+
dry-core (~> 0.4)
|
58
|
+
dry-equalizer (~> 0.2)
|
59
|
+
dry-initializer (~> 3.0)
|
60
|
+
dry-schema (~> 1.0, >= 1.3.1)
|
61
|
+
envlogic (1.1.0)
|
62
|
+
dry-inflector (~> 0.1)
|
63
|
+
irb (1.0.0)
|
64
|
+
karafka (1.3.0.rc1)
|
65
|
+
dry-configurable (~> 0.8)
|
66
|
+
dry-inflector (~> 0.1)
|
67
|
+
dry-monitor (~> 0.3)
|
68
|
+
dry-validation (~> 1.2)
|
69
|
+
envlogic (~> 1.0)
|
70
|
+
irb (~> 1.0)
|
71
|
+
multi_json (>= 1.12)
|
72
|
+
rake (>= 11.3)
|
73
|
+
ruby-kafka (>= 0.7.8)
|
74
|
+
thor (~> 0.20)
|
75
|
+
waterdrop (~> 1.3.0.rc1)
|
76
|
+
zeitwerk (~> 2.1)
|
77
|
+
king_konf (0.3.7)
|
78
|
+
multi_json (1.13.1)
|
79
|
+
rake (12.3.3)
|
80
|
+
ruby-kafka (0.7.9)
|
81
|
+
digest-crc
|
82
|
+
thor (0.20.3)
|
83
|
+
waterdrop (1.3.0.rc1)
|
84
|
+
delivery_boy (~> 0.2)
|
85
|
+
dry-configurable (~> 0.8)
|
86
|
+
dry-monitor (~> 0.3)
|
87
|
+
dry-validation (~> 1.2)
|
88
|
+
ruby-kafka (>= 0.7.8)
|
89
|
+
zeitwerk (~> 2.1)
|
90
|
+
zeitwerk (2.1.9)
|
91
|
+
|
92
|
+
PLATFORMS
|
93
|
+
ruby
|
94
|
+
|
95
|
+
DEPENDENCIES
|
96
|
+
karafka (= 1.3.0.rc1)
|
97
|
+
karafka-testing!
|
98
|
+
|
99
|
+
BUNDLED WITH
|
100
|
+
2.0.2
|
data/MIT-LICENCE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Karafka Testing library
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/karafka/testing.svg)](https://travis-ci.org/karafka/testing)
|
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 Travis CI](https://travis-ci.org/karafka/testing)
|
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)
|
data/certs/mensfeld.pem
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
|
3
|
+
ZWovREM9bWVuc2Zl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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,28 @@
|
|
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 = 'MIT'
|
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
|
+
if $PROGRAM_NAME.end_with?('gem')
|
24
|
+
spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.add_dependency 'karafka', '~> 1.3.0.rc1'
|
28
|
+
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,96 @@
|
|
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
|
+
App.consumer_groups.each do |consumer_group|
|
40
|
+
consumer_group.topics.each do |topic|
|
41
|
+
selected_topic = topic if topic.name == requested_topic.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
raise Karafka::Testing::Errors::TopicNotFoundError, requested_topic unless selected_topic
|
46
|
+
|
47
|
+
described_class.new(selected_topic)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Adds a new Karafka params instance with given payload and options into an internal
|
51
|
+
# buffer that will be used to simulate messages delivery to the consumer
|
52
|
+
#
|
53
|
+
# @param payload [String] anything you want to send
|
54
|
+
# @param opts [Hash] additional options with which you want to overwrite the
|
55
|
+
# message defaults (key, offset, etc)
|
56
|
+
#
|
57
|
+
# @example Send a json message to consumer
|
58
|
+
# before do
|
59
|
+
# publish_for_karafka({ 'hello' => 'world' }.to_json)
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# @example Send a json message to consumer and simulate, that it is partition 6
|
63
|
+
# before do
|
64
|
+
# publish_for_karafka({ 'hello' => 'world' }.to_json, 'partition' => 6)
|
65
|
+
# end
|
66
|
+
def publish_for_karafka(payload, opts = {})
|
67
|
+
_karafka_raw_data << Karafka::Params::Params
|
68
|
+
.new
|
69
|
+
.merge!(message_defaults)
|
70
|
+
.merge!('payload' => payload)
|
71
|
+
.merge!(opts)
|
72
|
+
|
73
|
+
subject.params_batch = Karafka::Params::ParamsBatch
|
74
|
+
.new(_karafka_raw_data)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# @return [Hash] message default options
|
80
|
+
def message_defaults
|
81
|
+
{
|
82
|
+
'deserializer' => subject.topic.deserializer,
|
83
|
+
'create_time' => Time.now,
|
84
|
+
'headers' => {},
|
85
|
+
'is_control_record' => false,
|
86
|
+
'key' => nil,
|
87
|
+
'offset' => 0,
|
88
|
+
'partition' => 0,
|
89
|
+
'receive_time' => Time.now,
|
90
|
+
'topic' => subject.topic.name
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
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.0.rc1
|
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+NME2C4ms0B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G/fhg1JV5vVDdVy6x+tv5SQ5ctU0feCsVfESi3rE3zRd+nvzE9HcZ5aXeL1UtJ
|
35
|
+
nT5Xrioegu2w1jPyVEgyZgTZC5rvD0nNS5sFNQ==
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
date: 2019-07-31 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.rc1
|
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.rc1
|
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
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CHANGELOG.md
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- MIT-LICENCE
|
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
|
+
- MIT
|
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: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.1
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.0.3
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Library which provides helpers for easier Karafka consumers tests
|
102
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|