google-pubsub-enhancer 0.5.5 → 0.5.7
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +11 -6
- data/lib/google_pubsub_enhancer/middleware/publisher.rb +1 -1
- data/lib/google_pubsub_enhancer/spec.rb +15 -1
- data/lib/google_pubsub_enhancer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 468a1c805763244fa09086b76a07509bceaabafc
|
4
|
+
data.tar.gz: 57bb90b802e4c3b4e73f75c1eb5608dd95734eb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cee422918c478a9a8b71ab0b77a2dba440fb1d7937500ee25f04eeadcd9d0f9174b49695adeccfb682893e208f6d45b957d87bba1d5652bf421112b599be7e46
|
7
|
+
data.tar.gz: 28dd4444715f981733eb8d9d907c6b35675fb2f585b81882dc5aa1cdcc0f69c8efd9914265faa8a9edf487806924d75766bc1a65a4d0725c7d2a2984dcb33f69
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -53,10 +53,14 @@ require 'spec_helper'
|
|
53
53
|
|
54
54
|
describe YourApplication do
|
55
55
|
|
56
|
+
#include the test framework for end to end testing
|
56
57
|
include GooglePubsubEnhancer::Spec
|
57
58
|
|
58
|
-
#
|
59
|
-
let(:messages) {[{foo:1}, {bar:2}]}
|
59
|
+
#set messages that come from a topic
|
60
|
+
let(:messages) {[JSON.dump({foo:1}), JSON.dump({bar:2})]}
|
61
|
+
|
62
|
+
#set expected_messages that you expect to publish after your middleware's work done
|
63
|
+
let(:expected_messages) { [{"foo" => 1}, {"bar" => 2}]}
|
60
64
|
|
61
65
|
it "should do the magic you write into" do
|
62
66
|
|
@@ -64,7 +68,9 @@ describe YourApplication do
|
|
64
68
|
|
65
69
|
# in this case the test middleware creates messages from pubsub objects
|
66
70
|
use YourMiddleware, -> env do
|
67
|
-
env[:messages_key] = env[:received_messages].map
|
71
|
+
env[:messages_key] = env[:received_messages].map do |msg|
|
72
|
+
JSON.parse msg.data
|
73
|
+
end
|
68
74
|
end
|
69
75
|
|
70
76
|
use GooglePubsubEnhancer::Middleware::Publisher,
|
@@ -72,9 +78,8 @@ describe YourApplication do
|
|
72
78
|
messages: :messages_key
|
73
79
|
end
|
74
80
|
|
75
|
-
# the only expectation you need
|
76
|
-
|
77
|
-
expect(publisher).to receive(:publish).with({bar:2}).ordered
|
81
|
+
# the only expectation you need
|
82
|
+
publish_called_with expected_messages
|
78
83
|
|
79
84
|
app.run 'subscription_short_name'
|
80
85
|
end
|
@@ -14,7 +14,7 @@ class GooglePubsubEnhancer::Middleware::Publisher
|
|
14
14
|
@logger.debug("#{env[@messages_key].length} messages published")
|
15
15
|
@google_cloud_pubsub.publish(@full_topic_name) do |publisher|
|
16
16
|
[*env[@messages_key]].each do |m|
|
17
|
-
publisher.publish(m)
|
17
|
+
publisher.publish(m, {recordId: Digest::MD5.hexdigest(m)} )
|
18
18
|
end
|
19
19
|
end
|
20
20
|
rescue => ex
|
@@ -5,7 +5,8 @@ module GooglePubsubEnhancer::Spec
|
|
5
5
|
let(:pubsub) {double "pubsub"}
|
6
6
|
let(:publisher) { double "publisher"}
|
7
7
|
let(:subscription) { double 'subscription'}
|
8
|
-
let(:google_messages) {messages.map { |m| Google::Cloud::Pubsub::Message.new(m
|
8
|
+
let(:google_messages) {messages.map { |m| Google::Cloud::Pubsub::Message.new(m)}}
|
9
|
+
|
9
10
|
before do
|
10
11
|
ENV['PUBSUB_KEYFILE_JSON'] = JSON.dump(project_id: 'cica')
|
11
12
|
allow(Google::Cloud::Pubsub).to receive(:new).and_return(pubsub)
|
@@ -14,6 +15,8 @@ module GooglePubsubEnhancer::Spec
|
|
14
15
|
allow(subscription).to receive(:pull).and_return(google_messages, nil)
|
15
16
|
allow(publisher).to receive(:publish)
|
16
17
|
allow(subscription).to receive(:acknowledge)
|
18
|
+
allow(Digest::MD5).to receive(:hexdigest).and_return("a1s2d3f4g5")
|
19
|
+
|
17
20
|
end
|
18
21
|
|
19
22
|
after do
|
@@ -22,9 +25,20 @@ module GooglePubsubEnhancer::Spec
|
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
28
|
+
module PublisherTester
|
29
|
+
def publish_called_with(messages)
|
30
|
+
messages.each do |msg|
|
31
|
+
expect(publisher).to receive(:publish).with(msg, {recordId: "a1s2d3f4g5"} )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
25
36
|
def self.included(klass)
|
26
37
|
klass.extend ClassMethods
|
27
38
|
klass.__setup_pubsub!
|
39
|
+
RSpec.configuration.include(PublisherTester)
|
28
40
|
end
|
29
41
|
|
42
|
+
|
43
|
+
|
30
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-pubsub-enhancer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bejczib
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|