Skip to content

Commit

Permalink
Use custom fake message to mock value to be a 'json' string
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Arcila-Valenzuela committed Nov 26, 2018
1 parent 7b29131 commit 7d5e387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/fake/kafka.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'fake/kafka/version'
require 'fake/kafka/consumer'
require 'fake/kafka/producer'
#require 'fake/kafka/message'
require 'fake/kafka/message'

module Fake
class Kafka
FakeMessage = Struct.new(:value, :key, :topic, :partition, :offset)
# Your code goes here...
attr_reader :messages, :paused_partitions

def initialize(*options)
Expand All @@ -20,7 +18,7 @@ def paused?(topic, partition)
end

def deliver_message(value, topic:)
@messages << FakeMessage.new(value, nil, topic, 0, 0)
@messages << Message.new(value, nil, topic, 0, 0)
end

def messages_in(topic)
Expand Down
14 changes: 14 additions & 0 deletions lib/fake/kafka/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Fake::Kafka::Message
attr_reader :key, :topic, :partition, :offset
def initialize(value, key, topic, partition, offset)
@value = value
@key = key
@topic = topic
@partition = partition
@offset = offset
end

def value
@value.to_json
end
end

0 comments on commit 7d5e387

Please sign in to comment.